Esempio n. 1
0
        // GET: BillingHold/Edit/5
        public async Task <IActionResult> Edit(int id)
        {
            var HoldModel = await _context.BillingHoldModel.SingleOrDefaultAsync(m => m.policy_Id == id);

            BillingHoldViewModel HoldViewModel = new BillingHoldViewModel();

            HoldViewModel.policy_Id = id;
            HoldViewModel.policy_No = this.FindPolicyNo(HoldModel.policy_Id);

            if (HoldModel == null)
            {
                return(NotFound());
            }
            if (HoldViewModel.policy_No == null)
            {
                return(NotFound());
            }
            else
            {
                HoldViewModel.ReleaseDate = HoldModel.ReleaseDate.AddDays(-1);
                HoldViewModel.Description = HoldModel.Description;
            }

            return(PartialView(HoldViewModel));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("policy_No,ReleaseDate,Description")] BillingHoldViewModel HoldViewModel)
        {
            var polisID = this.FindPolicyID(HoldViewModel.policy_No);
            var tgl     = DateTime.Now.Date;

            if (HoldViewModel.ReleaseDate < tgl)
            {
                ModelState.AddModelError("ReleaseDate", " HoldDate harus minimal tgl sekarang ");
            }
            if (polisID == 0)
            {
                ModelState.AddModelError("policy_No", "PolisNo Tidak Valid");
            }

            if (ModelState.IsValid)
            {
                var cmdx = _context.Database;
                var cmd  = _context.Database.GetDbConnection().CreateCommand();
                try
                {
                    cmdx.OpenConnection(); cmdx.BeginTransaction();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "hold_billing";
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(new MySqlParameter("@polis_id", MySqlDbType.Int32)
                    {
                        Value = polisID
                    });
                    cmd.Parameters.Add(new MySqlParameter("@release_date", MySqlDbType.Date)
                    {
                        Value = HoldViewModel.ReleaseDate
                    });
                    cmd.Parameters.Add(new MySqlParameter("@deskripsi", MySqlDbType.VarChar)
                    {
                        Value = HoldViewModel.Description
                    });

                    await cmd.ExecuteNonQueryAsync();

                    cmdx.CommitTransaction();
                }
                catch (Exception ex)
                {
                    cmdx.RollbackTransaction();
                    flashMessage.Danger(ex.Message);
                }
                finally
                {
                    if (cmdx.CurrentTransaction != null)
                    {
                        cmdx.RollbackTransaction();
                    }
                    cmdx.CloseConnection();
                }

                return(RedirectToAction("Index"));
            }
            return(View(HoldViewModel));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("policy_Id,policy_No,ReleaseDate,Description")] BillingHoldViewModel HoldViewModel)
        {
            var tgl = DateTime.Now.Date;

            if (HoldViewModel.ReleaseDate < tgl)
            {
                ModelState.AddModelError("ReleaseDate", " HoldDate harus minimal tgl sekarang ");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //BillingHoldModel HoldModel = new BillingHoldModel();
                    //HoldModel.policy_Id = id;
                    var HoldModel = _context.BillingHoldModel.SingleOrDefault(m => m.policy_Id == id);
                    HoldModel.ReleaseDate = HoldViewModel.ReleaseDate.AddDays(1);
                    HoldModel.Description = HoldViewModel.Description;
                    HoldModel.UserUpdate  = User.Identity.Name;
                    HoldModel.DateUpdate  = DateTime.Now;
                    _context.Update(HoldModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BillingHoldModelExists(HoldViewModel.policy_Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(HoldViewModel));
        }