Beispiel #1
0
        public AccountType()
        {
            InitializeComponent();
            AccountTypeViewModel atvm = new AccountTypeViewModel();

            this.DataContext = atvm;
        }
Beispiel #2
0
 public ActionResult AddEditAccountType(long?id, AccountTypeViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             bool        isNew       = !id.HasValue;
             AccountType accountType = isNew ? new AccountType
             {
                 //AddedDate = DateTime.UtcNow
             } : accountTypeRepository.GetAccountType(id.Value);
             accountType.accTypeName = model.accTypeName;
             if (isNew)
             {
                 accountTypeRepository.SaveAccountType(accountType);
             }
             else
             {
                 accountTypeRepository.UpdateAccountType(accountType);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(RedirectToAction("Index"));
 }
Beispiel #3
0
 public async Task <AccountTypeViewModel> EncodeAccountTypeId(AccountTypeViewModel accountType)
 {
     return(await Task.Run(() =>
     {
         accountType.AccountTypeId = GuidEncoder.Encode(accountType.AccountTypeId);
         return accountType;
     }));
 }
        public ViewAccountType()
        {
            InitializeComponent();
            AccountTypeViewModel _ATVM = new AccountTypeViewModel();

            _ATVM.GetAccountTypeList();
            this.DataContext = _ATVM;
        }
Beispiel #5
0
        public async Task <IActionResult> Put(int id, [FromBody] AccountTypeViewModel model)
        {
            model = await service.Update(id, model);

            if (model == null)
            {
                return(BadRequest());
            }
            return(Ok(model));
        }
Beispiel #6
0
        public async Task <IActionResult> Post([FromBody] AccountTypeViewModel value)
        {
            value = await service.Create(value);

            if (value == null)
            {
                return(BadRequest());
            }
            return(CreatedAtAction("Get", new { id = value.Id }, value));
        }
Beispiel #7
0
        public IActionResult DeleteAccountType(long id)
        {
            AccountType          accountType = accountTypeRepository.GetAccountType(id);
            AccountTypeViewModel model       = new AccountTypeViewModel
            {
                accTypeName = $"{accountType.accTypeName}"
            };

            return(PartialView("~/Views/AccountTypes/_DeleteAccountType.cshtml", model));
        }
        /// <summary>
        /// Delete an entity.
        /// </summary>
        /// <param name="model"></param>
        public void Delete(AccountTypeViewModel model)
        {
            var entity = model.ToEntity();

            this._AccountTypesRepository.Delete(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion
        }
Beispiel #9
0
        public ActionResult Create(AccountTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var account = Mapper.Map <AccountType>(model);
                account.OwnerId = User.Identity.GetUserId();
                _unitOfWork.AccountTypes.Add(account);
                _unitOfWork.Complete();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Beispiel #10
0
        /// <summary>
        /// Insert new AccountType item.
        /// </summary>
        /// <param name="model">The AccountType information value.</param>
        /// <returns></returns>
        public ResultViewModel Save(AccountTypeViewModel model)
        {
            var result = new ResultViewModel();

            using (TransactionScope scope = new TransactionScope())
            {
                var accountType = _mapper.Map <AccountTypeViewModel, AccountType>(model);
                _unitOfWork.GetRepository <AccountType>().Add(accountType);
                _unitOfWork.Complete(scope);
            }
            this.ReloadCacheAccountType();
            return(result);
        }
Beispiel #11
0
        /// <summary>
        /// Update AccountType item.
        /// </summary>
        /// <param name="model">The AccountType information value.</param>
        /// <returns></returns>
        public ResultViewModel Edit(AccountTypeViewModel model)
        {
            var result = new ResultViewModel();

            using (TransactionScope scope = new TransactionScope())
            {
                var accountType = _unitOfWork.GetRepository <AccountType>().GetCache(x => x.Id == model.Id).FirstOrDefault();
                accountType.TypeName = model.TypeName;
                _unitOfWork.GetRepository <Data.Pocos.AccountType>().Update(accountType);
                _unitOfWork.Complete(scope);
            }
            this.ReloadCacheAccountType();
            return(result);
        }
Beispiel #12
0
        public IActionResult AddEditAccountType(long?id)
        {
            AccountTypeViewModel model = new AccountTypeViewModel();

            if (id.HasValue)
            {
                AccountType accountType = accountTypeRepository.GetAccountType(id.Value); if (accountType != null)
                {
                    model.accTypeId   = accountType.accTypeId;
                    model.accTypeName = accountType.accTypeName;
                }
            }
            return(PartialView("~/Views/AccountTypes/_AddEditAccountType.cshtml", model));
        }
        /// <summary>
        /// Update an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public AccountTypeViewModel Update(AccountTypeViewModel model)
        {
            this.ThrowExceptionIfExist(model);

            var entity = model.ToEntity();

            entity = this._AccountTypesRepository.Update(entity);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion

            model = entity.ToModel();
            return(model);
        }
        /// <summary>
        /// Throw an exception if name is exist.
        /// </summary>
        /// <param name="model">AccountType view model</param>
        public void ThrowExceptionIfExist(AccountTypeViewModel model)
        {
            ConditionFilter <AccountType, long> condition = new ConditionFilter <AccountType, long>
            {
                Query = (entity =>
                         entity.Name == model.Name &&
                         entity.Id != model.Id)
            };
            var existEntity = this._AccountTypesRepository.Get(condition).FirstOrDefault();

            if (existEntity != null)
            {
                throw new ItemAlreadyExistException();
            }
        }
Beispiel #15
0
 public ActionResult Edit(int id, AccountTypeViewModel model)
 {
     if (ModelState.IsValid)
     {
         // ensure the id is valid and belongs to this user.
         var accountType = _unitOfWork.AccountTypes.Get(id);
         if (accountType == null)
         {
             return(HttpNotFound());
         }
         if (accountType.OwnerId != UserId)
         {
             return(new HttpUnauthorizedResult("You are not authorized to edit this record."));
         }
         Mapper.Map(model, accountType);
         _unitOfWork.AccountTypes.Update(accountType);
         _unitOfWork.Complete();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
 public IActionResult Edit([FromBody] AccountTypeViewModel model)
 {
     return(Ok(_accountType.Edit(model)));
 }
 public IActionResult Save([FromBody] AccountTypeViewModel model)
 {
     return(Ok(_accountType.Save(model)));
 }