Пример #1
0
        public async Task <ActionResult <Client> > Post(ClientCreate entity)
        {
            try
            {
                var client    = _mapper.Map <Client>(entity);
                var itemCount = await _clientService.CreateAsync(client);

                if (entity.ClientContacts != null && entity.ClientContacts.Count > 0)
                {
                    var clientContacts = _mapper.Map <List <ClientContact> >(entity.ClientContacts);

                    foreach (var item in clientContacts)
                    {
                        item.ClientId = client.Id;
                        await _genericClientContactService.CreateAsync(item);
                    }
                }

                if (itemCount > 0)
                {
                    var item = await _clientService.GetByIdAsync(client.Id);

                    return(CreatedAtAction(nameof(Get), new { id = client.Id }, item));
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #2
0
        public async Task <IActionResult> Create(ClientCreate model)
        {
            if (model.MobileNumber.StartsWith('0'))
            {
                model.MobileNumber = "962" + model.MobileNumber.Substring(1);
            }
            else
            {
                model.MobileNumber = "962" + model.MobileNumber;
            }
            bool existUsername     = _db.ApplicationUsers.FirstOrDefault(x => x.UserName == model.Username) == null ? false : true;
            bool existMobileNumber = _db.ApplicationUsers.FirstOrDefault(x => x.MobileNumber == model.MobileNumber) == null ? false : true;

            if (existUsername)
            {
                throw new Exception("اسم المستخدم مستخدم");
            }
            if (existMobileNumber)
            {
                throw new Exception("رقم الهاتف مستخدم");
            }
            long            userId = _principalService.GetUserId();
            ApplicationUser user   = new ApplicationUser
            {
                CreatedAt    = DateTime.Now,
                CreatedBy    = userId,
                Email        = model.Email,
                FullName     = model.ClientFullName,
                IsActive     = true,
                MobileNumber = model.MobileNumber,
                UserName     = model.Username,
                UserGuid     = Guid.NewGuid()
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                CreateRoleIfNotExist("Client", user.Id);
                Client client = new Client
                {
                    Address        = model.Address,
                    CreatedAt      = DateTime.Now,
                    CreatedBy      = userId,
                    ClientFullName = model.ClientFullName,
                    Email          = model.Email,
                    MobileNumber   = model.MobileNumber,
                    UserId         = user.Id,
                    IsActive       = true,
                    CLientGuid     = Guid.NewGuid()
                };
                _db.Clients.Add(client);
                var added = _db.SaveChanges();
                AddAreaGroupPriceForClientId(client.Id);
                return(new OkObjectResult(1));
            }
            throw new Exception("حصل خطأ");
        }
Пример #3
0
 public Client(ClientCreate command)
 {
     Title             = command.Title;
     LegalEntity       = command.LegalEntity;
     ClientType        = command.ClientType;
     NumberOfCalls     = command.NumberOfCalls;
     NumberOfShipments = command.NumberOfShipments;
     Group             = command.Group;
 }
Пример #4
0
        public ActionResult Create(ClientCreate model)
        {
            if (ModelState.IsValid)
            {
                var service = CreateClientService();
                service.CreateClient(model);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Пример #5
0
        public async Task <IActionResult> Create([FromBody] ClientCreate model)
        {
            try
            {
                var result = await _clientService.Create(model);

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #6
0
 public ActionResult Cadastrar(ClientCreate model)
 {
     try
     {
         var client = Mapper.Map<ClientCreate, Client>(model);
         _clientService.Insert(client);
         return RedirectToAction("Index");
     }
     catch
     {
         return View(model);
     }
 }
Пример #7
0
        public bool CreateClient(ClientCreate model)
        {
            var entity = new Client
            {
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Email       = model.Email,
                PhoneNumber = model.PhoneNumber,
                Address     = model.Address
            };

            _context.Clients.Add(entity);
            return(_context.SaveChanges() == 1);
        }
Пример #8
0
        public async Task <IActionResult> Post([FromBody] ClientCreate command)
        {
            var currentManagerId = _accountInformationService.GetOperatorId();

            var client = await _context.Set <Client>()
                         .AddAsync(new Client(command));



            var workGroup = await _context.Set <WorkGroup>()
                            .FirstOrDefaultAsync(x => x.EscortManagerId == currentManagerId ||
                                                 x.RegionalManagerId == currentManagerId);

            workGroup.BindClient(new BindClient()
            {
                ClientId    = client.Entity.Id,
                WorkgroupId = workGroup.Id
            });

            foreach (var phone in command.Phones)
            {
                await _context.Set <ClientPhone>()
                .AddAsync(new ClientPhone()
                {
                    ClientId = client.Entity.Id,
                    Phone    = phone.Phone
                });
            }

            await _context.SaveChangesAsync();

            var result = new ClientDto
            {
                Id                = client.Entity.Id,
                Title             = client.Entity.Title,
                LegalEntity       = client.Entity.LegalEntity,
                ClientType        = client.Entity.ClientType,
                NumberOfCalls     = client.Entity.NumberOfCalls,
                NumberOfShipments = client.Entity.NumberOfShipments,
                Group             = (int)client.Entity.Group,
                Phones            = _context.Set <ClientPhone>().Where(z => z.ClientId == client.Entity.Id).Select(z => new ClientPhoneDTO
                {
                    Id    = z.Id,
                    Phone = z.Phone
                }).ToList(),
            };

            return(Ok(result));
        }
Пример #9
0
        public IHttpActionResult Post(ClientCreate client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateClientService();

            if (!service.CreateClient(client))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Пример #10
0
        public bool CreateClient(ClientCreate model)
        {
            var entity =
                new Client()
            {
                CustomerId  = _userId,
                ClientName  = model.ClientName,
                ClientCity  = model.ClientCity,
                ClientNeeds = model.ClientNeeds,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Clients.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Пример #11
0
        public ActionResult NewSaleCreate(ClientCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateClientService();

            if (service.CreateClient(model))
            {
                TempData["SaveResult"] = "Your client was added.";
                return(RedirectToAction("Create", "Sale"));
            }
            ;

            ModelState.AddModelError("", "Client could not be added.");
            return(RedirectToAction("Create", "Sale", model));
        }
        public bool CreateClient(ClientCreate model)
        {
            var entity =
                new Client()
            {
                OwnerID     = _userId,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Address     = model.Address,
                PhoneNumber = model.PhoneNumber,
                Email       = model.Email,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Clients.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Пример #13
0
        public async Task <IActionResult> Post([FromBody] ClientCreate command)
        {
            var client = await _context.Set <Client>()
                         .AddAsync(new Client(command));

            foreach (var phone in command.Phones)
            {
                await _context.Set <ClientPhone>()
                .AddAsync(new ClientPhone()
                {
                    ClientId = client.Entity.Id,
                    Phone    = phone.Phone
                });
            }

            await _context.SaveChangesAsync();

            var clientPhones = await _context.Set <ClientPhone>()
                               .ToListAsync();

            var result = new ClientDto()
            {
                Id          = client.Entity.Id,
                Title       = client.Entity.Title,
                LegalEntity = client.Entity.LegalEntity,
                Phones      = clientPhones.Where(z => z.ClientId == client.Entity.Id).Select(z => new ClientPhoneDTO {
                    Id       = z.Id,
                    ClientId = client.Entity.Id,
                    Phone    = z.Phone
                }).ToList(),
                ClientType        = client.Entity.ClientType,
                NumberOfCalls     = client.Entity.NumberOfCalls,
                NumberOfShipments = client.Entity.NumberOfShipments,
                HasWorkgroup      = _context.Set <ClientWorkGroup>().Any(x => x.ClientId == client.Entity.Id),
                Group             = (int)client.Entity.Group
            };

            return(Ok(result));
        }
Пример #14
0
        /*public IQueryable<Manager> GetManagers(int clientId)
         * {
         *  return _managerForClientRepository.All()
         *      .Where(x => x.ClientId == clientId)
         *      .Select(x => x.Manager);
         * }*/

        public Client Create(ClientCreate command)
        {
            return(_clientRepository.Create(
                       new Client(command)));
        }
Пример #15
0
 public IActionResult Post([FromBody] ClientCreate command)
 {
     return(Ok(_clientService.Create(command)));
 }
 public async Task<ClientCreate.response> ClientCreate(ClientCreate.request request, CancellationToken? token = null)
 {
     return await SendAsync<ClientCreate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }