--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
public async Task<HttpStatusCodeResult> Confirm(ConfirmOrderModel model){ if (ModelState.IsValid) { var order = await Raven.LoadAsync<Order>(model.Id);
if (order == null) return HttpNotFound();
if (order.Status == Order.StatusType.Accepted) return Ok();
order.Status = Order.StatusType.Accepted; order.AcceptedOn = DateTime.UtcNow; order.DeliveryDuration = model.DeliveryDuration;
await Raven.SaveChangesAsync(); await Tasks.PushAsync(new OrderStatusChangeMessage { Order = order.Id });
return Ok(); } else { return BadRequest(); }}That is pretty clean looking code. I think you won me over. By the way, why are you returning HttpStatusCodeResult, are you utilizing ASP.NET MVC as a REST back end?
On Tuesday, July 23, 2013 1:15:13 PM UTC-4, Mircea Chirea wrote:Khalid, just call SaveChangesAsync in the action after you are done with writing to the database. Sometimes copy-pasting is good; this is one of those cases. This way you'll know at a glance whether and when your changes are persisted to the database. I mean:public async Task<HttpStatusCodeResult> Confirm(ConfirmOrderModel model){if (ModelState.IsValid){var order = await Raven.LoadAsync<Order>(model.Id);if (order == null)return HttpNotFound();if (order.Status == Order.StatusType.Accepted)return Ok();order.Status = Order.StatusType.Accepted;order.AcceptedOn = DateTime.UtcNow;order.DeliveryDuration = model.DeliveryDuration;await Raven.SaveChangesAsync();await Tasks.PushAsync(new OrderStatusChangeMessage{Order = order.Id});return Ok();}else{return BadRequest();}}
--
SRP > DRY :-]
--
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using EuMananc.Data.Raven.Documents;using Raven.Client;
namespace EuMananc.Web.Mvc{ public abstract partial class Controller : ControllerBase { /*\ *** *** *** *** *** Properties *** *** *** *** *** \*/ new public Account User { get; private set; }
/*\ *** *** *** *** *** Database Properties *** *** *** *** *** \*/ protected IAsyncDocumentSession Raven { get; private set; }
/*\ *** *** *** *** *** Constructor *** *** *** *** *** \*/ protected Controller() { Raven = Application.Raven.OpenAsyncSession(); }
/*\ *** *** *** *** *** Protected Methods *** *** *** *** *** \*/ protected override async Task OnBeforeExecuteAsync() { if (!Application.IsAuthenticated()) return;
User = await Raven.LoadAsync<Account>(Application.User.Id); }
protected override void Dispose(bool disposing) { if (disposing) { using (Raven) Raven = null; }
base.Dispose(disposing); } }}