コード例 #1
0
        public IActionResult AddOrEdit(int id, CustomerGroupDto customergroup)
        {
            // var id1 = this.GetGroupId(customer);
            if (ModelState.IsValid)
            {
                if (id == 0)
                {
                    customerGroupService.CreateCustomerGroup(customergroup);
                }
                else
                {
                    try
                    {
                        customerGroupService.UpdateCustomerGroup(customergroup);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!customerGroupService.CustomerGroupExists(customergroup.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                var customergroups = customerGroupService.GetAll();
                return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAll", customergroups) }));
            }

            return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", customergroup) }));
        }
コード例 #2
0
        public async Task <IActionResult> Put([FromBody] CustomerGroupDto model)
        {
            if (!await _permissionService.Authorize(PermissionSystemName.Customers))
            {
                return(Forbid());
            }

            var customerGroup = await _mediator.Send(new GetQuery <CustomerGroupDto>() { Id = model.Id });

            if (!customerGroup.Any())
            {
                return(NotFound());
            }

            if (ModelState.IsValid && !model.IsSystem)
            {
                model = await _mediator.Send(new UpdateCustomerGroupCommand()
                {
                    Model = model
                });

                return(Ok(model));
            }
            return(BadRequest(ModelState));
        }
コード例 #3
0
 //Map from Dto to Entity
 public static CustomerGroup MappingGroup(this CustomerGroupDto customerGroupDto)
 {
     return(new CustomerGroup
     {
         Id = customerGroupDto.Id,
         Name = customerGroupDto.Name
     });
 }
コード例 #4
0
        public string create(CustomerGroupDto tCustomerGroupDto)
        {
            try
            {
                CustomerGroup tCustomerGroupNew = mapper.Map <CustomerGroupDto, CustomerGroup>(tCustomerGroupDto);
                tCustomerGroupNew.Id         = Guid.NewGuid().ToString();
                tCustomerGroupNew.CreateDate = DateTime.Now;

                _context.CustomerGroup.Add(tCustomerGroupNew);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
コード例 #5
0
        public async Task <IActionResult> Post([FromBody] CustomerGroupDto model)
        {
            if (!await _permissionService.Authorize(PermissionSystemName.Customers))
            {
                return(Forbid());
            }

            if (ModelState.IsValid)
            {
                model = await _mediator.Send(new AddCustomerGroupCommand()
                {
                    Model = model
                });

                return(Created(model));
            }
            return(BadRequest(ModelState));
        }
コード例 #6
0
        //Update
        public string update(CustomerGroupDto tCustomerGroupDto)
        {
            try
            {
                CustomerGroup tCustomerGroupUpdate = _context.CustomerGroup.Find(tCustomerGroupDto.Id);
                if (tCustomerGroupUpdate == null)
                {
                    return("1");
                }
                tCustomerGroupUpdate.Name       = tCustomerGroupDto.Name;
                tCustomerGroupUpdate.Id         = tCustomerGroupDto.Id;
                tCustomerGroupUpdate.Status     = tCustomerGroupDto.Status;
                tCustomerGroupUpdate.CreateDate = tCustomerGroupDto.CreateDate;
                tCustomerGroupUpdate.CreateUser = tCustomerGroupDto.CreateUser;

                _context.CustomerGroup.Update(tCustomerGroupUpdate);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception ex)
            {
                return("1");
            }
        }
コード例 #7
0
        public string update(CustomerGroupDto customerGroupDto)
        {
            try
            {
                CustomerGroup customerGroupUpdate = _context.CustomerGroup.Find(customerGroupDto.Id);
                if (customerGroupUpdate == null)
                {
                    return("1");
                }
                customerGroupUpdate.Id         = customerGroupDto.Id;
                customerGroupUpdate.Name       = customerGroupDto.Name;
                customerGroupUpdate.Status     = customerGroupDto.Status;
                customerGroupUpdate.CreateDate = customerGroupDto.CreateDate;
                customerGroupUpdate.CreateUser = customerGroupDto.CreateUser;

                _context.CustomerGroup.Update(customerGroupUpdate);
                _context.SaveChanges();
                return("");
            }
            catch (Exception)
            {
                return("1");
            }
        }
コード例 #8
0
        public IActionResult Update([FromBody] CustomerGroupDto value)
        {
            string result = _bbService.update(value);

            return(new ObjectResult(result));
        }
コード例 #9
0
 //Map from Dto to Entity
 public static void MappingGroup(this CustomerGroupDto customerGroupDto, CustomerGroup customerGroup)
 {
     customerGroup.Id   = customerGroupDto.Id;
     customerGroup.Name = customerGroupDto.Name;
 }
コード例 #10
0
 public void UpdateCustomerGroup(CustomerGroupDto customerGroupDto)
 {
     customerGroupRepository.Update(customerGroupDto.MappingGroup());
 }
コード例 #11
0
 public void DeleteCustomerGroup(CustomerGroupDto customerGroupDto)
 {
     customerGroupRepository.Delete(customerGroupDto.MappingGroup());
 }
コード例 #12
0
 public void CreateCustomerGroup(CustomerGroupDto customerGroupDto)
 {
     customerGroupRepository.Add(customerGroupDto.MappingGroup());
 }
コード例 #13
0
 public static CustomerGroup ToEntity(this CustomerGroupDto model, CustomerGroup destination)
 {
     return(model.MapTo(destination));
 }
コード例 #14
0
 public static CustomerGroup ToEntity(this CustomerGroupDto model)
 {
     return(model.MapTo <CustomerGroupDto, CustomerGroup>());
 }