//[Authorize(Roles = "...")] public ActionResult SaveReferralOrder(ReferralOrderTemplate referralOrderTemplate) { try { using (var db = new StoreContext()) { int?cnt = db.ReferralOrderItems.Where(p => p.ReferralOrderId == referralOrderTemplate.ReferralOrderId).Count(); if (cnt == 0) { var referralOrder = new ReferralOrder(); referralOrder.ReferralOrderId = referralOrderTemplate.ReferralOrderId; referralOrder.ReferralId = referralOrderTemplate.ReferralId; referralOrder.ConfirmOrderDate = referralOrderTemplate.ConfirmOrderDate; referralOrder.ReferralOrderDate = referralOrderTemplate.ReferralOrderDate; referralOrder.OrganizationId = referralOrderTemplate.OrganizationId; referralOrder.ReferralOrderStatusId = 1; referralOrder.Id = userId; referralOrder.LogDate = db.Database.SqlQuery <DateTime>("SELECT GETDATE()").Single(); db.ReferralOrders.Add(referralOrder); } else { ReferralOrder item = db.ReferralOrders.Find(referralOrderTemplate.ReferralOrderId); item.ReferralId = referralOrderTemplate.ReferralId; item.ConfirmOrderDate = referralOrderTemplate.ConfirmOrderDate; item.ReferralOrderDate = referralOrderTemplate.ReferralOrderDate; item.OrganizationId = referralOrderTemplate.OrganizationId; item.ReferralOrderStatusId = referralOrderTemplate.ReferralOrderStatusId; item.Id = userId; item.LogDate = db.Database.SqlQuery <DateTime>("SELECT GETDATE()").Single(); db.Entry(item).State = EntityState.Modified; } db.SaveChanges(); return(Json(new { success = true, responseText = "" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new { success = false, responseText = ex.Message }, JsonRequestBehavior.AllowGet)); } }
//[Authorize(Roles = "...")] public ActionResult ReferralOrderTemplate(int?id, int?referralId) { try { using (var db = new StoreContext()) { this.ViewBugs(db); if (id == 0) { Referral referral = db.Referrals.Find(referralId); var item = new ReferralOrderTemplate(); item.ReferralId = referralId; item.ConfirmationDate = referral.ConfirmationDate; item.ValidityDate = referral.ValidityDate; item.ReferralOrderStatusId = 1; return(View("ReferralOrderTemplate", item)); } else { ReferralOrderItem referralOrderItem = db.ReferralOrderItems.Find(id); var referralOrderTemplate = new ReferralOrderTemplate(); referralOrderTemplate.ReferralOrderId = referralOrderItem.ReferralOrderId; referralOrderTemplate.ReferralId = referralOrderItem.ReferralId; referralOrderTemplate.ReferralOrderDate = referralOrderItem.ReferralOrderDate; referralOrderTemplate.ConfirmationDate = referralOrderItem.ConfirmationDate; referralOrderTemplate.ConfirmOrderDate = referralOrderItem.ConfirmOrderDate; referralOrderTemplate.OrganizationId = referralOrderItem.OrganizationId; referralOrderTemplate.ValidityDate = referralOrderItem.ValidityDate; referralOrderTemplate.ReferralOrderStatusId = referralOrderItem.ReferralOrderStatusId; return(View("ReferralOrderTemplate", referralOrderTemplate)); } } } catch (Exception ex) { return(RedirectToAction("Index", "Error", new { msg = ex.Message })); } }