コード例 #1
0
        public async Task <AjaxResult> Update([FromBody] CustomerInputDto dto)
        {
            return(await AjaxResult.Business(async result =>
            {
                Check.NotNull(dto, nameof(dto));

                if (!ModelState.IsValid)
                {
                    result.Error("提交信息验证失败");
                    return;
                }
                if (String.IsNullOrWhiteSpace(dto.Operator))
                {
                    dto.Operator = User.Identity.Name;
                }
                dto.DateTime = DateTime.Now;
                await _customerContract.UpdateCustomerAsync(dto);
                result.Type = AjaxResultType.Success;
                if (dto == null)
                {
                    result.Error("找不到指定的客户信息");
                }
                else
                {
                    result.Success(dto);
                }
            }));
        }
コード例 #2
0
        public int Add(CustomerInputDto entity)
        {
            Notification notification = ValidationInsert(entity);

            if (notification.HasErrors())
            {
                throw new ArgumentException(notification.ErrorMessage());
            }

            var identityUserWithSameEmail = _unitOfWork.IdentityUsers.GetByEmail(entity.Email);

            var identityUserWithSameUserName = _unitOfWork.IdentityUsers.GetByUserName(entity.UserName);

            var newIdentityUser = new IdentityUser(entity.UserName, entity.Email, entity.Password, "member", entity.Active);

            _identityUserDomainService.PerformNewUser(newIdentityUser, identityUserWithSameEmail, identityUserWithSameUserName);

            _unitOfWork.IdentityUsers.Add(newIdentityUser);

            var customer = Mapper.Map <Customer>(entity);

            var customerWithSameDni = _unitOfWork.Customers.GetByDni(entity.Dni);

            _customerDomainService.PerformNewCustomer(customer, customerWithSameDni, newIdentityUser.Id);

            _unitOfWork.Customers.Add(customer);

            _unitOfWork.Complete();

            return(customer.Id);
        }
コード例 #3
0
        public int Update(int id, CustomerInputDto entity)
        {
            var customer = _unitOfWork.Customers.Get(id);

            _unitOfWork.Customers.Update(customer);
            _unitOfWork.Complete();

            return(customer?.Id ?? 0);
        }
コード例 #4
0
        public int Add(CustomerInputDto entity)
        {
            var customer = Mapper.Map <Customer>(entity);

            _unitOfWork.Customers.Add(customer);

            _unitOfWork.Complete();

            return(customer.Id);
        }
コード例 #5
0
        public async Task <ActionResult <Customer> > PostCustomer(CustomerInputDto input)
        {
            try
            {
                if (input.UserId == "")
                {
                    input.UserId = null;
                }
                if (input.UpdatedUserId == "")
                {
                    input.UpdatedUserId = null;
                }
                var existed = await _context.Customers.Where(x => x.Email == input.Email).FirstOrDefaultAsync();

                if (existed != null)
                {
                    return(null);
                }
                var customer = new Customer()
                {
                    FirstName     = input.FirstName,
                    LastName      = input.LastName,
                    Country       = input.Country,
                    City          = input.City,
                    IpAddress     = input.IpAddress,
                    Phone         = input.Phone,
                    UserId        = input.UserId,
                    Blocked       = false,
                    Email         = input.Email,
                    CreatedDate   = DateTime.Now,
                    CreatedUserId = input.UpdatedUserId
                };
                IdentityResult IR   = null;
                var            user = new User {
                    UserName = (input.Email), Email = input.Email, PhoneNumber = input.Phone, IsCustomer = true
                };
                IR = await _userManager.CreateAsync(user, input.Password);

                if (!IR.Succeeded)
                {
                    return(null);
                }
                var usr = await _userManager.FindByEmailAsync(input.Email);

                customer.UserId = usr.Id;
                _context.Customers.Add(customer);
                await _context.SaveChangesAsync();

                return(customer);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #6
0
        public async Task <ActionResult <CustomerInputDto> > GetCustomerByUserId(string id)
        {
            var customer = await _context.Customers.FirstOrDefaultAsync(x => x.UserId == id);

            if (customer == null)
            {
                return(NotFound());
            }
            var output = new CustomerInputDto()
            {
                Id        = customer.Id,
                FirstName = customer.FirstName,
                LastName  = customer.LastName,
                Country   = customer.Country,
                City      = customer.City,
                Phone     = customer.Phone,
                Email     = customer.Email,
            };

            return(output);
        }
コード例 #7
0
        public async Task <ActionResult <Customer> > PutCustomer(int id, CustomerInputDto input)
        {
            var customer = await _context.Customers.FindAsync(id);

            var usr = await _userManager.FindByIdAsync(input.UserId);

            usr.Email                      = input.Email;
            usr.PhoneNumber                = input.Phone;
            customer.FirstName             = input.FirstName;
            customer.LastName              = input.LastName;
            customer.Email                 = input.Email;
            customer.Country               = input.Country;
            customer.City                  = input.City;
            customer.Phone                 = input.Phone;
            customer.UpdatedUserId         = input.UpdatedUserId;
            customer.UpdatedDate           = DateTime.Now;
            _context.Entry(customer).State = EntityState.Modified;
            _context.Entry(usr).State      = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(customer);
        }
コード例 #8
0
 public IActionResult Post([FromBody] CustomerInputDto customer)
 {
     _customerApplicationService.Add(customer);
     return(Ok("customer was added sucessfully"));
 }
コード例 #9
0
        private Notification ValidationInsert(CustomerInputDto entity)
        {
            Notification notification = new Notification();

            if (entity == null)
            {
                notification.AddError("Invalid JSON data in request body");
                return(notification);
            }

            if (string.IsNullOrEmpty(entity.Dni))
            {
                notification.AddError("DNI is missing");
            }
            else if (entity.Dni.Length != 8)
            {
                notification.AddError("DNI should have 8 numbers");
            }

            if (string.IsNullOrEmpty(entity.FirstName))
            {
                notification.AddError("FirstName is missing");
            }
            else if (entity.FirstName.Length < 2)
            {
                notification.AddError("FirstName should have min 2 characters");
            }

            if (string.IsNullOrEmpty(entity.LastName))
            {
                notification.AddError("LastName is missing");
            }
            else if (entity.LastName.Length < 2)
            {
                notification.AddError("LastName should have min 2 characters");
            }

            if (string.IsNullOrEmpty(entity.UserName))
            {
                notification.AddError("UserName is missing");
            }
            else if (entity.UserName.Length < 4)
            {
                notification.AddError("UserName should have min 4 characters");
            }

            if (string.IsNullOrEmpty(entity.Password))
            {
                notification.AddError("Password is missing");
            }
            else if (entity.Password.Length < 6)
            {
                notification.AddError("Password should have min 6 characters");
            }

            if (!IsValidEmail(entity.Email))
            {
                notification.AddError("Email is not valid");
                return(notification);
            }

            return(notification);
        }
コード例 #10
0
        public async Task <bool> UpdateCustomerAsync(CustomerInputDto dto)
        {
            var customer = dto.MapTo <Customer>();

            return(await _customerRepo.UpdateAsync(customer) > 0);
        }
コード例 #11
0
        public async Task <bool> AddCustomerAsync(CustomerInputDto dto)
        {
            var customer = dto.MapTo <Customer>();

            return(await _customerRepo.InsertAsync(customer) > 0);
        }
コード例 #12
0
        public async Task <ActionResult <CustomerDto> > PutCustomer(int id, CustomerInputDto input)
        {
            DateTime?dateime  = null;
            var      customer = await _context.Customers.FindAsync(id);

            customer.FullName              = input.FullName;
            customer.BirthDate             = DateTimeString.TryParsingDate(input.BirthDate, false);
            customer.Address               = input.Address;
            customer.City                  = input.City;
            customer.Country               = input.Country;
            customer.Email                 = input.Email;
            customer.Gender                = input.Gender;
            customer.Phone                 = input.Phone;
            customer.PostalCode            = input.PostalCode;
            customer.UpdatedUserId         = input.UserId;
            customer.UpdatedDate           = DateTime.Now;
            customer.Note                  = input.Note;
            _context.Entry(customer).State = EntityState.Modified;
            var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == input.UserId);

            var log = new Log()
            {
                DateTime     = DateTime.Now,
                TypeFullName = typeof(Domain.Entities.Customer).FullName,
                Content      = "@userName@updateAction@objTitle",
                TypeId       = customer.Id,
                UserId       = user.Id
            };

            _context.Logs.Add(log);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            var result = new CustomerDto()
            {
                Id         = customer.Id,
                FullName   = customer.FullName,
                BirthDate  = customer.BirthDate,
                Address    = customer.Address,
                City       = customer.City,
                Country    = customer.Country,
                Email      = customer.Email,
                Gender     = customer.Gender,
                Phone      = customer.Phone,
                PostalCode = customer.PostalCode
            };

            return(result);
        }
コード例 #13
0
        public async Task <ActionResult <CustomerDto> > PostCustomer(CustomerInputDto input)
        {
            try
            {
                DateTime?dateime  = null;
                var      customer = new Domain.Entities.Customer()
                {
                    FullName      = input.FullName,
                    Address       = input.Address,
                    City          = input.City,
                    Country       = input.Country,
                    BirthDate     = DateTimeString.TryParsingDate(input.BirthDate, false),
                    Email         = input.Email,
                    Gender        = input.Gender,
                    Phone         = input.Phone,
                    PostalCode    = input.PostalCode,
                    CreatedDate   = DateTime.Now,
                    CreatedUserId = input.UserId,
                    Note          = input.Note
                };
                _context.Customers.Add(customer);
                await _context.SaveChangesAsync();

                //var course = new Course()
                //{
                //    ExamDate = dateime,
                //    InChargeId = input.InChargeId,
                //    CustomerId = customer.Id,
                //    LessonPeriod = Domain.Enums.LessonPeriod.TwoHours,
                //    Note = input.Note,
                //    StartCourse = DateTimeString.TryParsingDate(input.StartCourse, false),
                //    TotalAmount = 0,
                //    CurrencyId = null,
                //    PeroidBeforeSendEmailId = null,
                //    TypeOfExamId = null,
                //    TypeOfPacketId = null,
                //    CreatedDate = DateTime.Now,
                //    CreatedUserId = input.UserId
                //};
                //course.RemainingMoney = course.TotalAmount;
                //course.Status = Domain.Enums.CourseStatus.NotStarted;
                //_context.Courses.Add(course);
                var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == input.UserId);

                var log = new Log()
                {
                    DateTime     = DateTime.Now,
                    TypeFullName = typeof(Domain.Entities.Customer).FullName,
                    Content      = "@userName@addAction@objTitle",
                    TypeId       = customer.Id,
                    UserId       = user.Id
                };
                _context.Logs.Add(log);
                await _context.SaveChangesAsync();

                var result = new CustomerDto()
                {
                    Id         = customer.Id,
                    FullName   = customer.FullName,
                    BirthDate  = customer.BirthDate,
                    Address    = customer.Address,
                    City       = customer.City,
                    Country    = customer.Country,
                    Email      = customer.Email,
                    Gender     = customer.Gender,
                    Phone      = customer.Phone,
                    PostalCode = customer.PostalCode
                };
                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #14
0
 public HttpResponseMessage Put(CustomerInputDto dto)
 {
     dto.CheckNotNull("dto");
     return Request.CreateResponse(customer.Edit(dto));
 }