Пример #1
0
        public void CreatePerson(PersonEntity personEntity)
        {
            personEntity.IdPerson       = Guid.NewGuid();
            personEntity.CreatedDate    = DateTime.Now;
            personEntity.UpdatedDate    = DateTime.Now;
            personEntity.IdOrganization = Guid.NewGuid();
            personEntity.UserName       = personEntity.Email;

            _personsRepository.Add(personEntity);
        }
        public IActionResult Post([FromBody] Person person)
        {
            if (person != null)
            {
                _persons.Add(person);
                return(new OkResult());
            }

            return(new NotFoundResult());
        }
Пример #3
0
        public int AddPerson(PersonBusiness personBusiness)
        {
            var person = new Person()
            {
                CI        = personBusiness.CI,
                Direction = personBusiness.Direction,
                FirstName = personBusiness.FirstName,
                LastName  = personBusiness.LastName,
                Mail      = personBusiness.Mail,
                Telephone = personBusiness.Telephone
            };

            return(_personRepository.Add(person));
        }
        /// <summary>
        /// validate person object and add it to database
        /// </summary>
        /// <param name="person"></param>
        /// <returns>return PersonResult(Errors object and Result json object if no validating object passed)</returns>
        public PersonResult Add(PersonRequest person)
        {
            var result = new PersonResult();
            var error  = ValidatePerson(person);

            if (!error.HasErrors)
            {
                result.Result = JsonConvert.SerializeObject(_personsRepository.Add(person));
            }
            else
            {
                result.Errors = error;
            }

            return(result);
        }
Пример #5
0
        public ActionResult Add(AddUserModel model)
        {
            //10a. Dodajemy akcje do zapisania usera w repository
            // Najpierw robimy walidację, poźniej sprawdzamy modalstate, walidacja jest utworzona w folderze validate
            Validate(model);


            if (ModelState.IsValid)
            {
                _personsRepository.Add(model);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(model));
            }
        }
Пример #6
0
        public Order CreateOrder(CreateOrderQuery createOrderQuery)
        {
            Person person = _personsRepository.Add(new Person
            {
                Email       = createOrderQuery.Person.Email,
                FirstName   = createOrderQuery.Person.FirstName,
                LastName    = createOrderQuery.Person.LastName,
                MiddleName  = createOrderQuery.Person.MiddleName,
                PhoneNumber = createOrderQuery.Person.PhoneNumber
            });

            Order order = _ordersRepository.Add(new Order
            {
                Person            = person,
                AdditionalComment = createOrderQuery.AdditionalComment
            });

            _orderStatusHistoryItemsRepository.Add(new OrderStatusHistoryItem
            {
                Created = DateTime.Now,
                OrderId = order.Id,
                Status  = OrderStatus.Open
            });

            foreach (CreateOrderQuery.AddOrderedProductQuery addOrderedProductQuery in createOrderQuery.OrderedProducts)
            {
                Product product = _productsRepository.GetById(addOrderedProductQuery.ProductId);
                _orderedProductsRepository.Add(new OrderedProduct
                {
                    ProductId = addOrderedProductQuery.ProductId,
                    Product   = product,
                    Quantity  = addOrderedProductQuery.Quantity,
                    OrderId   = order.Id,
                    PriceAtTheTimeOfPurchase = product.PriceInTheMainCurrency
                });
                order.TotalAmount += product.PriceInTheMainCurrency * addOrderedProductQuery.Quantity;
            }

            _ordersRepository.Update(order);

            NotifyAboutOrder(order);

            return(order);
        }
Пример #7
0
        public IUserAccount Create(IUserAccount account)
        {
            List <KeyValuePair <string, string> > accountFailedValidations = account.Validate();

            if (accountFailedValidations.Any())
            {
                throw new ValidationFailedException(accountFailedValidations);
            }

            //Validate if email doesn't exist
            IPerson personWithEmail = _personsRepository.GetByEmail(account.Email);

            if (personWithEmail.Id != 0)
            {
                throw new EmailAlreadyInUseException($"Email '{account.Email}' is already in use");
            }

            IPerson personDb = new PersonDTO()
            {
                Email        = account.Email,
                PersonTypeId = (int)account.PersonType,
                Name         = account.Name,
                LastName     = account.LastName
            };

            _personsRepository.Add(personDb);
            _uow.Save();

            IPerson  savedPerson = _personsRepository.GetByEmail(account.Email);
            IAccount accountDb   = new AccountDTO()
            {
                IsActive           = true,
                AccountTypeId      = (int)account.AccountType,
                IdentityProviderId = account.IdentityProviderId,
                PersonId           = savedPerson.Id
            };

            _accountsRepository.Add(accountDb);
            _uow.Save();

            IAccountDetail createdAccount = _accountsRepository.GetByIdentityProviderId(account.IdentityProviderId);

            return(new UserAccount(createdAccount));
        }
        public IActionResult Post([FromBody] string name)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try {
                var id        = Guid.NewGuid().ToString();
                var newPerson = new Person {
                    Id = id, Name = name
                };
                _personsRepository.Add(newPerson);
                return(CreatedAtRoute("GetPerson", new { Id = id }, newPerson));
            }
            // This can be a better handler
            catch (Exception ex) {
                _logger.LogError(ex, "Unable to create request: Person", null);
                return(StatusCode(500));
            }
        }
Пример #9
0
 public Person Add(Person person)
 {
     return(_personsRepository.Add(person));
 }