Example #1
0
        /// <summary>
        /// Saves a new Creditor or updates an already existing Creditor.
        /// </summary>
        /// <param name="Creditor">Creditor to be saved or updated.</param>
        /// <param name="CreditorId">CreditorId of the Creditor creating or updating</param>
        /// <returns>CreditorId</returns>
        public long SaveCreditor(CreditorDTO creditorDTO, string userId)
        {
            long creditorId = 0;

            if (creditorDTO.CreditorId == 0)
            {
                var creditor = new Creditor()
                {
                    AspNetUserId   = creditorDTO.AspNetUserId,
                    CasualWorkerId = creditorDTO.CasualWorkerId,
                    BranchId       = creditorDTO.BranchId,
                    Amount         = creditorDTO.Amount,
                    Action         = creditorDTO.Action,
                    SectorId       = creditorDTO.SectorId,
                    CreatedOn      = DateTime.Now,
                    TimeStamp      = DateTime.Now,
                    CreatedBy      = userId,
                    Deleted        = false,
                };

                this.UnitOfWork.Get <Creditor>().AddNew(creditor);
                this.UnitOfWork.SaveChanges();
                creditorId = creditor.CreditorId;
                return(creditorId);
            }

            else
            {
                var result = this.UnitOfWork.Get <Creditor>().AsQueryable()
                             .FirstOrDefault(e => e.CreditorId == creditorDTO.CreditorId);
                if (result != null)
                {
                    result.AspNetUserId   = creditorDTO.AspNetUserId;
                    result.CasualWorkerId = creditorDTO.CasualWorkerId;
                    result.Amount         = creditorDTO.Amount;
                    result.Action         = creditorDTO.Action;
                    result.BranchId       = creditorDTO.BranchId;
                    result.SectorId       = creditorDTO.SectorId;
                    result.UpdatedBy      = userId;
                    result.TimeStamp      = DateTime.Now;
                    result.Deleted        = creditorDTO.Deleted;
                    result.DeletedBy      = creditorDTO.DeletedBy;
                    result.DeletedOn      = creditorDTO.DeletedOn;

                    this.UnitOfWork.Get <Creditor>().Update(result);
                    this.UnitOfWork.SaveChanges();
                }
                return(creditorDTO.CreditorId);
            }
        }
Example #2
0
        public IActionResult UpdateCreditor(CreditorDTO creditor)
        {
            string username = this.HttpContext.Session.GetString(SessionConstant.UserNameSession);

            if (string.IsNullOrEmpty(username))
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!ModelState.IsValid)
            {
                return(View("EditCreditInsurance", creditor));
            }

            var customerInDb = _customerRepository.GetCustomerById(creditor.Id);

            if (customerInDb == null)
            {
                TempData["Fail"] = "Cập nhật dữ liệu thất bại !";
                return(RedirectToAction("Index"));
            }

            customerInDb.CiName      = creditor.CiName;
            customerInDb.CiDate      = DateTime.ParseExact(creditor.CiDate, "dd/MM/yyyy", null);
            customerInDb.CiRemarks   = creditor.CiRemarks;
            customerInDb.PaySlip     = creditor.PaySlip;
            customerInDb.ValidId     = creditor.ValidId;
            customerInDb.Cert        = creditor.Cert;
            customerInDb.Cedula      = creditor.Cedula;
            customerInDb.Income      = creditor.Income;
            customerInDb.UpdatedBy   = "admin";
            customerInDb.UpdatedDate = DateTime.Now;
            bool isSuccess = this._customerRepository.UpdateCustomer(customerInDb);

            if (isSuccess)
            {
                TempData["Success"] = "Cập nhật dữ liệu thành công !";
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["Fail"] = "Cập nhật dữ liệu thất bại !";
                return(RedirectToAction("Index"));
            }
        }