public UpdateReport UpdateAgreement(Agreement agreement)
        {
            SebContext context = null;

            try
            {
                context = new SebContext();

                var id      = agreement.Id;
                var current = context.Agreements.Include(x => x.Customer).First(x => x.Id == id);

                var oldBaseRateCode = current.BaseRateCode;
                current.BaseRateCode = agreement.BaseRateCode;

                var report = CalculationReport.Build(current, oldBaseRateCode).Result;

                // if we are here let save new value
                context.SaveChanges();

                return(ToUpdateReport(report));
            }
            catch
            {
                return(UpdateReport.Failed);
            }
            finally
            {
                context?.Dispose();
            }
        }
 public ActionResult Create([Bind(Include = "FirstName, LastName, PersonalId")] SebCustomer customer)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Customers.Add(customer);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (RetryLimitExceededException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(customer));
 }
        public ActionResult CreatePost(int?SelectedCustomer)
        {
            var vm = new ViewModels.NewAgreement();

            try
            {
                if (TryUpdateModel(vm, "", new string[] { "CustomerId", "Amount", "BaseRateCode", "Margin", "Duration" }))
                {
                    var masterCustomer = db.Customers.Find(vm.CustomerId);

                    if (masterCustomer != null)
                    {
                        var agreement = new SebCustomerAgreement
                        {
                            Amount       = vm.Amount,
                            BaseRateCode = vm.BaseRateCode,
                            Margin       = vm.Margin,
                            Duration     = vm.Duration,
                            Customer     = masterCustomer
                        };

                        db.Agreements.Add(agreement);
                        db.SaveChanges();

                        return(RedirectToAction("Index", new { SelectedCustomer = masterCustomer.Id }));
                    }
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            PopulateBaseRateCodes(null);
            return(View(vm));
        }