コード例 #1
0
        public async Task<ActionResult> Create(CustomerViewModel viewmodel)
        {
            if (ModelState.IsValid)
            {
                MSTCustomerDto cus = new MSTCustomerDto
                {
                    CustomerName = viewmodel.Name,
                    EndCustomer = viewmodel.EndCustomer,
                    Location = viewmodel.Location,
                    Strategic = viewmodel.Strategic,
                    LastUpdatedBy = CurrentName
                };
                var result = await CustomerRepository.AddAsync(cus);

                if (result == Model.SaveResult.SUCCESS)
                    return RedirectToAction("Index");
            }

            return View(viewmodel);
        }
コード例 #2
0
        /// <summary>
        /// Adds the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> AddAsync(MSTCustomerDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_Customer add = context.MST_Customer.Create();

                    add.CustomerName = entity.CustomerName;
                    add.EndCustomer = entity.EndCustomer;
                    add.Location = entity.Location;
                    add.Strategic = entity.Strategic;
                    add.IsDeleted = entity.IsDeleted;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<MST_Customer>(add).State = System.Data.Entity.EntityState.Added;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
コード例 #3
0
        /// <summary>
        /// Deletes the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> DeleteAsync(MSTCustomerDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var cus = context.MST_Customer.Single(x => x.Id == entity.Id && x.IsDeleted == false);
                    cus.IsDeleted = true;

                    context.Entry<MST_Customer>(cus).State = System.Data.Entity.EntityState.Modified;
                    result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return result;
        }
コード例 #4
0
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(MSTCustomerDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var cus = context.MST_Customer.Single(x => x.Id == entity.Id && x.IsDeleted == false);

                    cus.CustomerName = entity.CustomerName;
                    cus.EndCustomer = entity.EndCustomer;
                    cus.Location = entity.Location;
                    cus.Strategic = entity.Strategic;
                    cus.IsDeleted = entity.IsDeleted;
                    cus.LastUpdatedBy = entity.LastUpdatedBy;
                    cus.LastUpdate = DateTime.Now;

                    context.Entry<MST_Customer>(cus).State = System.Data.Entity.EntityState.Modified;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return result;
        }