예제 #1
0
 private void CustomerItemsOf3lists(CustomerEditModel model, Guid id)
 {
     foreach (var item in model.CustomerContacts)
     {
         item.CustomerID  = id;
         item.CreatedDate = !string.IsNullOrEmpty(model.CreatedDate)
             ? DateTime.Parse(model.CreatedDate).ToString() : DateTime.Now.ToString();
         item.CreatedByUserID = _principal.Id.ToString();
         item.UpdatedDate     = DateTime.Now.ToString();
         item.UpdatedByUserID = _principal.Id.ToString();
         item.IsActive        = true;
     }
     foreach (var item in model.CustomerDepartments)
     {
         item.CustomerID  = id;
         item.CreatedDate = !string.IsNullOrEmpty(model.CreatedDate)
             ? DateTime.Parse(model.CreatedDate).ToString() : DateTime.Now.ToString();
         item.CreatedBy   = _principal.Id.ToString();
         item.UpdatedDate = DateTime.Now.ToString();
         item.UpdatedBy   = _principal.Id.ToString();
         item.IsActive    = true;
     }
     foreach (var item in model.CustomerLocations)
     {
         item.CustomerID  = id;
         item.CreatedDate = !string.IsNullOrEmpty(model.CreatedDate)
             ? DateTime.Parse(model.CreatedDate).ToString() : DateTime.Now.ToString();
         item.CreatedBy   = _principal.Id.ToString();
         item.UpdatedDate = DateTime.Now.ToString();
         item.UpdatedBy   = _principal.Id.ToString();
         item.IsActive    = true;
     }
 }
예제 #2
0
        private CustomerEditModel BuildCustomerEditModel(Customer entity)
        {
            var customerEditModel = new CustomerEditModel();

            customerEditModel.CustomerID          = entity.CustomerID;
            customerEditModel.CustomerCode        = entity.CustomerCode;
            customerEditModel.CustomerCompanyName = entity.CustomerCompanyName;
            customerEditModel.ParentCustomerID    = entity.ParentCustomerID;
            customerEditModel.ParentCustomerName  = entity.ParentCustomer.CustomerCompanyName;
            customerEditModel.IsTransfer          = entity.IsTransfer;
            customerEditModel.Statements          = entity.Statements;
            customerEditModel.CompanyID           = entity.CompanyID;
            customerEditModel.CompanyName         = entity.Company.CompanyName;
            if (entity.NoteID.HasValue)
            {
                customerEditModel.NoteID = entity.NoteID;
                entity.Note             = _noteService.NoteById(entity.NoteID.Value);
                customerEditModel.Notes = entity.Note.NoteText;
            }
            customerEditModel.IsActive            = entity.IsActive ?? true;
            customerEditModel.CreatedDate         = entity.CreatedDate.HasValue ? entity.CreatedDate.ToString() : string.Empty;
            customerEditModel.CreatedBy           = entity.CreatedBy.HasValue ? entity.CreatedBy.Value.ToString() : string.Empty;
            customerEditModel.UpdatedDate         = entity.UpdatedDate.HasValue ? entity.UpdatedDate.ToString() : string.Empty;
            customerEditModel.UpdatedBy           = entity.UpdatedBy.HasValue ? entity.UpdatedBy.Value.ToString() : string.Empty;
            customerEditModel.CustomerLocations   = _locationOrchestra.BuildCustomerLocationModels(entity.CustomerLocations);
            customerEditModel.CustomerDepartments = _departmentOrchestra.BuildCustomerDepartmentModels(entity.CustomerDepartments);
            customerEditModel.CustomerContacts    = _contactOrchestra.BuildCustomerContactModels(entity.CustomerContacts);
            return(customerEditModel);
        }
예제 #3
0
        public ActionResult Edit(int id, CustomerEditModel customer)
        {
            if (ModelState.IsValid)
            {
                if (_customerRepository.IsExists(id))
                {
                    customer.CustomerId = id;
                    try
                    {
                        var result = _customerRepository.UpdateCustomer(customer);

                        if (result)
                        {
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            ModelState.AddModelError("", $"Error update customer with {id} ID");
                        }
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("", e);
                    }
                }
                else
                {
                    return(HttpNotFound($"Can not find customer with {id} ID"));
                }
            }

            ViewBag.Roles = GetSelectListItem(customer);
            return(View((Customer)customer));
        }
예제 #4
0
        public ActionResult Update(CustomerEditModel model)
        {
            JsonResultModel result = new JsonResultModel();

            try
            {
                Validate validate = new Validate();
                validate.CheckObjectArgument <CustomerEditModel>("model", model);
                if (validate.IsFailed)
                {
                    result.BuilderErrorMessage(validate.ErrorMessages);
                    return(Json(result));
                }
                model.PostValidate(validate);
                if (validate.IsFailed)
                {
                    result.BuilderErrorMessage(validate.ErrorMessages);
                    return(Json(result));
                }
                this.customerService.Update(model.Id, model.Name, model.Nickname, model.Mobile, model.WeChatId, model.GroupId, this.Session["Mobile"].ToString());
                result.Result = true;
            }
            catch (EasySoftException ex)
            {
                result.BuilderErrorMessage(ex.Message);
            }
            catch (Exception ex)
            {
                result.BuilderErrorMessage(ex.Message);
            }
            return(Json(result));
        }
예제 #5
0
 public CustomerEditModel CreateCustomer(CustomerEditModel model)
 {
     try
     {
         var item = ApplyChanges(model);
         item.NoteID = SaveNote(model);
         if (model.CustomerID == Guid.Empty)
         {
             model.CustomerID = PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]);
             item.CustomerID  = model.CustomerID;
             item.ObjectState = ObjectState.Added;
             _customerService.Insert(item);
         }
         else
         {
             item.ObjectState = ObjectState.Modified;
             _customerService.Update(item);
         }
         SaveCustomerDataIn3lists(model);
     }
     catch (Exception ex)
     {
         throw new ApplicationException("Creating Customer failed", ex);
     }
     return(model);
 }
예제 #6
0
        public async Task EditAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var customerRepo = new EfDeletableEntityRepository <Customer>(dbContext);

            var service = new CustomerService(customerRepo);

            var id = await service.CreateAsync <CustomerModel>(new CustomerModel
            {
                FirstName = "ivan",
                LastName  = "ivanov",
            });

            var model = new CustomerEditModel
            {
                Id        = id,
                FirstName = "Dragan",
                LastName  = "Draganov",
            };

            await service.EditAsync <CustomerEditModel>(model);

            var customer = await customerRepo.All()
                           .FirstOrDefaultAsync(x => x.Id == id);

            Assert.Equal(id, customer.Id);
            Assert.Equal("Dragan", customer.FirstName);
            Assert.Equal("Draganov", customer.LastName);
        }
예제 #7
0
        public async Task <IActionResult> Edit(CustomerEditModel input)
        {
            var employerAccount = await this.userManager.GetUserAsync(this.User);

            var employerId = await this.employeesManagerService.GetEmployersIdAsync(employerAccount.Id);

            if (input.EmployerId != employerId)
            {
                return(this.NotFound());
            }
            try
            {
                await this.customersService.UpdateAsync(input);
            }
            catch (Exception e)
            {
                this.ModelState.AddModelError(string.Empty, e.Message);
            }

            if (!ModelState.IsValid)
            {
                return(this.View(input));
            }

            await this.notificationsService.CreateNotificationAsync(
                employerAccount.ParentId,
                $"{employerAccount.FullName} edited {input.FirstName} {input.LastName} as him customer");

            return(this.RedirectToAction("Index"));
        }
예제 #8
0
        public ActionResult Edit(int id, CustomerEditModel itemRaw)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var itemDto = new CustomerDTO
                    {
                        Id      = id,
                        Name    = itemRaw.Name,
                        Address = itemRaw.Address,
                    };

                    CustomerService.Update(itemDto);

                    return(RedirectToAction("Index"));
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError(ex.Property, ex.Message);
                }
            }

            return(View(itemRaw));
        }
예제 #9
0
        public async Task UpdateAsync(CustomerEditModel input)
        {
            var customer = await this.customersRepository
                           .All()
                           .FirstOrDefaultAsync(x => x.Id == input.Id);

            if (await this.IsExistEmail(input.Email, input.OwnerId) && customer.Email != input.Email)
            {
                throw new Exception($"You already have customer with email: {input.Email}");
            }

            if (await this.IsExistPhone(input.PhoneNumber, input.OwnerId) && customer.PhoneNumber != input.PhoneNumber)
            {
                throw new Exception($"You already have customer with phone: {input.PhoneNumber}");
            }



            customer.PhoneNumber    = input.PhoneNumber;
            customer.Email          = input.Email;
            customer.EmployerId     = input.EmployerId;
            customer.FirstName      = input.FirstName;
            customer.MiddleName     = input.MiddleName;
            customer.LastName       = input.LastName;
            customer.AdditionalInfo = input.AdditionalInfo;

            await this.addressService.UpdateAsync(customer.AddressId, input.AddressCountry, input.AddressCity, input.AddressStreet,
                                                  input.AddressZipCode);

            customer.JobTitleId = await this.jobTitlesService.CreateAsync(input.JobTitleName);

            this.customersRepository.Update(customer);

            await this.customersRepository.SaveChangesAsync();
        }
예제 #10
0
        public async Task <IActionResult> Edit(CustomerEditModel input)
        {
            var owner = await this.userManager.GetUserAsync(this.User);

            if (owner.Id != input.OwnerId)
            {
                return(this.NotFound());
            }

            try
            {
                await this.customersService.UpdateAsync(input);
            }
            catch (Exception e)
            {
                this.ModelState.AddModelError(string.Empty, e.Message);
            }

            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            return(this.RedirectToAction("Index"));
        }
예제 #11
0
        public async Task EditAsync(CustomerEditModel model)
        {
            var customer = await _customerRepository.GetAsync(model.Id);

            CustomerFactory.Update(model, customer, _userId);
            _customerRepository.Edit(customer);
            await _unitOfWork.SaveChangesAsync();
        }
        public ActionResult EditPost([FromQuery] int id, CustomerEditModel model)
        {
            var customer = _session.Get <Customer>(id);

            customer.Firstname = model.Firstname;
            customer.Lastname  = model.Lastname;
            return(Redirect("/Customer"));
        }
예제 #13
0
        public CustomerEditModel GetCustomerModelByCustomerID(Guid customerID)
        {
            Customer          entity        = _customerService.GetCustomerByIdFromRepo(customerID);
            CustomerEditModel customerModel = entity != null
                ? BuildCustomerEditModel(entity)
                : null;

            return(customerModel);
        }
예제 #14
0
        // GET: Products/Create
        public ActionResult Create()
        {
            var item = new CustomerEditModel
            {
                Name    = "",
                Address = "",
            };

            return(View(item));
        }
예제 #15
0
        private Guid UpdateNote(CustomerEditModel model, ApplicationUser author)
        {
            var note = _noteService.Find(model.NoteID.Value);

            note.NoteText        = model.Notes;
            note.NoteDescription = model.NoteDescription;
            note.ObjectState     = ObjectState.Modified;
            _noteService.Update(note);
            return(note.NoteID);
        }
예제 #16
0
        public ActionResult Edit(CustomerEditModel customerEM)
        {
            Customer customer = customerService.GetCustomerByCode(customerEM.Code);

            customer.Name     = customerEM.Name;
            customer.Address  = customerEM.Address;
            customer.Discount = customerEM.Discount;
            customerService.EditCustomer(customer);
            return(RedirectToAction("Index"));
        }
예제 #17
0
        public async Task <IActionResult> Create([FromForm] CustomerEditModel model)
        {
            var customer = new Customer();

            _mapper.Map(model, customer);

            customer.AccountId = GerUserAccountId();
            await _customerRepository.StoreNewAsync(customer);

            return(RedirectToAction("Index"));
        }
예제 #18
0
        public ViewResult Create()
        {
            var customerModel = new CustomerEditModel();

            ViewBag.FormAspAction = "Create";

            customerModel.FirstName = "Dummy";
            customerModel.LastName  = "Test";
            customerModel.Title     = "Mr";
            customerModel.Email     = "*****@*****.**";

            return(View("Edit", customerModel));
        }
예제 #19
0
        public ActionResult Edit(CustomerEditModel model)
        {
            if (this.ModelState.IsValid)
            {
                var customer = this.Mapper.Map<Customer>(model);
                this.customers.Update(model.Id, customer);
                TempData["Success"] = GlobalConstants.CustomerUpdateNotify;
                
                return this.Redirect("/Admin/Customers/Index");
            }

            return this.View(model);
        }
예제 #20
0
        public CustomerEditModel CustomerUpdate(string id_customer, string name)
        {
            ENDPOINT  = body.getQueryUpdateCustomer(_PUBLIC_KEY, id_customer);
            PARAMETER = body.getBodyUpdateCustomer(name);
            string content = _request.Execute(
                ENDPOINT,
                "POST",
                _auxiliars.ConvertToBase64(_PUBLIC_KEY),
                PARAMETER);
            CustomerEditModel customer = JsonConvert.DeserializeObject <CustomerEditModel>(content);

            return(customer);
        }
예제 #21
0
        private Guid CreateNote(CustomerEditModel model, ApplicationUser author)
        {
            var note = new Note
            {
                NoteID          = PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]),
                NoteText        = model.Notes,
                NoteDescription = model.NoteDescription,
                // IsActive = true,
                ObjectState = ObjectState.Added
            };

            _noteService.Insert(note);
            return(note.NoteID);
        }
예제 #22
0
        public ActionResult Edit(string id, string name, string groupId, int page = 1)
        {
            Customer          entity = this.customerService.Select(id);
            CustomerEditModel model  = new CustomerEditModel(entity);

            if (string.IsNullOrWhiteSpace(model.WeChatId))
            {
                model.WeChatId = WebResource.Common_None;
            }
            model.QueryName    = name;
            model.QueryGroupId = groupId;
            model.PageIndex    = page;
            return(View(model));
        }
        public IActionResult OnPostUpdate(int id, [FromForm] CustomerEditModel model)
        {
            var customer = _database.Customers.First(c => c.Id == id);

            if (!ModelState.IsValid)
            {
                return(Partial("_CustomerForm", customer));
            }

            customer.FirstName    = model.FirstName;
            customer.LastName     = model.LastName;
            customer.EmailAddress = model.EmailAddress;

            return(Partial("_CustomerDetail", customer));
        }
        public async Task <ActionResult> ManagerEdit2(CustomerEditModel model)
        {
            List <AppUser> ap   = new List <AppUser>();
            AppUser        user = new AppUser();

            foreach (string userId in model.IdsToEdit ?? new string[] { })
            {
                user = await _userManager.FindByIdAsync(userId);

                ap.Add(user);
            }


            return(View("EditEmployees", user));
        }
예제 #25
0
        public HttpResponseMessage Edit([FromBody] CustomerEditModel editModel)
        {
            if (!ModelState.IsValid)
            {
                var validationErrors = ModelState.Values
                                       .SelectMany(_ => _.Errors.Select(x => x.ErrorMessage));
                return(Request.CreateResponse((HttpStatusCode)422, validationErrors));
            }
            var edited = Service.Edit(editModel);

            if (edited)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound));
        }
        public IActionResult Edit(int id, CustomerEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            bool result = this.customers.Edit(id, model.Name, model.BirthDate);

            if (!result)
            {
                return(BadRequest());
            }

            return(Redirect("/"));
        }
예제 #27
0
        public async Task <IActionResult> Edit(int Id, [FromForm] CustomerEditModel model)
        {
            var customer = await _customerRepository.GetByIdAsync(Id);

            if (customer == null)
            {
                Response.StatusCode = NotFound().StatusCode;
                return(View("Customer not found!"));
            }

            _mapper.Map(model, customer);

            await _customerRepository.UpdateAsync(customer);

            return(RedirectToAction("Index"));
        }
예제 #28
0
        public IActionResult CustomerEdit([FromRoute] int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                AppointDom uptmodel = new AppointDom();
                uptmodel = _svc.GetById(id);

                if (uptmodel == null)
                {
                    return(NotFound());
                }
                //seperate date
                string res1 = uptmodel.Appoint.ToString("yyyy-MM-dd");
                string res2 = uptmodel.Appoint.ToString("HH:mm");

                //build model
                CustomerEditModel model = new CustomerEditModel();
                model.Id           = uptmodel.Id;
                model.UserId       = uptmodel.UserId;
                model.CustFName    = uptmodel.CustFName;
                model.CustLName    = uptmodel.CustLName;
                model.Street       = uptmodel.Street;
                model.City         = uptmodel.City;
                model.State        = uptmodel.State;
                model.Zip          = uptmodel.Zip;
                model.Email        = uptmodel.Email;
                model.Phone        = uptmodel.Phone;
                model.AppointDate  = res1;
                model.AppointTime  = res2;
                model.ModifiedBy   = uptmodel.ModifiedBy;
                model.IsCnfrmed    = uptmodel.IsCnfrmed;
                model.ReminderSent = uptmodel.ReminderSent;
                model.CompName     = uptmodel.CompName;
                model.CompEmail    = uptmodel.CompEmail;

                return(View(model));
            }
            catch (Exception ex)
            {
                return(StatusCode(457, ex));
            }
        }
예제 #29
0
        private void SaveCustomerDataIn3lists(CustomerEditModel model)
        {
            Dictionary <string, Guid> locaDic = new Dictionary <string, Guid>();
            Dictionary <string, Guid> depaDic = new Dictionary <string, Guid>();

            foreach (var item in model.CustomerLocations)
            {
                var result = _locationOrchestra.CreateCustomerLocation(item);
                //if (IsIdGuid(item.CustomerLocationID.ToString())) ///////////////////////////
                if (!item.ItemAdding && !item.ItemDeleting)
                {
                    item.x_CustomerLocationID = item.CustomerLocationID.ToString();
                }
                locaDic[item.x_CustomerLocationID] = result.CustomerLocationID;
            }
            foreach (var item in model.CustomerDepartments)
            {
                var locaGuidList = new List <Guid>();
                foreach (var xId in item.SelectedLocationIds)
                {
                    locaGuidList.Add(locaDic[xId]);
                }
                var result = _departmentOrchestra.CreateCustomerDepartment(item, locaGuidList);
                //if (IsIdGuid(item.CustomerDepartmentID.ToString())) //////////////////////////
                if (!item.ItemAdding && !item.ItemDeleting)
                {
                    item.x_CustomerDepartmentID = item.CustomerDepartmentID.ToString();
                }
                depaDic[item.x_CustomerDepartmentID] = result.CustomerDepartmentID;
            }
            foreach (var item in model.CustomerContacts)
            {
                var locaGuidList = new List <Guid>();
                foreach (var xId in item.SelectedLocationIds)
                {
                    locaGuidList.Add(locaDic[xId]);
                }
                var depaGuidList = new List <Guid>();
                foreach (var xId in item.SelectedDepartmentIds)
                {
                    depaGuidList.Add(depaDic[xId]);
                }
                _contactOrchestra.CreateCustomerContact(item, locaGuidList, depaGuidList);
            }
        }
예제 #30
0
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            try
            {
                var itemDto = CustomerService.Get(id);
                var item    = new CustomerEditModel
                {
                    Name    = itemDto.Name,
                    Address = itemDto.Address
                };

                return(View(item));
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
        }
예제 #31
0
        public IActionResult Create(CustomerEditModel model)
        {
            if (ModelState.IsValid)
            {
                var customer = new Customer();
                model.UpdateEntity(customer);
                _context.Clients.Add(customer);
                _context.SaveChanges();

                model.UpdateDistricts(customer);
                model.UpdateHousingTypes(customer);
                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View("Save", model));
        }