public Model.WishlistListing Save(WishlistListingInsertRequest request)
        {
            var entity = _mapper.Map <Database.WishlistListing>(request);

            _context.WishlistListing.Add(entity);
            _context.SaveChanges();
            return(_mapper.Map <Model.WishlistListing>(entity));
        }
Beispiel #2
0
        public Model.ListingResponse Insert(ListingInsertRequest listing)
        {
            try
            {
                var entity = new Database.Listing
                {
                    Address            = listing.Address,
                    AreaDescription    = listing.AreaDescription,
                    Bathrooms          = listing.Bathrooms,
                    Beds               = listing.Beds,
                    City               = listing.City,
                    ListingDescription = listing.ListingDescription,
                    Approved           = false,
                    DateCreated        = DateTime.Now,
                    DateApproved       = new DateTime(),
                    Name               = listing.Name,
                    Persons            = listing.Persons,
                    TerritoryId        = listing.TerritoryId,
                    UserId             = listing.UserId
                };
                _context.Listing.Add(entity);
                _context.SaveChanges();

                foreach (var item in listing.Amenities)
                {
                    var ListingAmenity = new ListingAmenity();
                    ListingAmenity.ListingId = entity.ListingId;
                    ListingAmenity.AmenityId = item;
                    _context.ListingAmenity.Add(ListingAmenity);
                    _context.SaveChanges();
                }

                return(new ListingResponse
                {
                    ListingId = entity.ListingId,
                    Message = "Uspješno dodan oglas",
                    Status = true
                });
            }
            catch (Exception ex)
            {
                return(new ListingResponse
                {
                    Message = ex.Message,
                    Status = false
                });
            }
        }
Beispiel #3
0
        public Model.User Insert(UserUpsertRequest request)
        {
            if (_context.User.Any(x => x.Email == request.Email))
            {
                throw new UserException("Email \"" + request.Email + "\" je već zauzet!");
            }
            var entity = _mapper.Map <Database.User>(request);

            if (request.Password != request.PasswordConfirmation)
            {
                throw new UserException("Lozinke se ne podudaraju!");
            }

            entity.PasswordSalt = GenerateSalt();
            entity.PasswordHash = GenerateHash(entity.PasswordSalt, request.Password);

            _context.User.Add(entity);
            _context.SaveChanges();

            var wishlist = new Database.Wishlist {
                UserId = entity.UserId
            };

            _context.Wishlist.Add(wishlist);
            _context.SaveChanges();

            if (request.Roles != null && request.Roles.Count() > 0 && request.Roles[0] != 0)
            {
                foreach (var role in request.Roles)
                {
                    _context.UserRole.Add(new UserRole
                    {
                        RoleId = role,
                        UserId = entity.UserId
                    });
                }
            }
            _context.SaveChanges();
            return(_mapper.Map <Model.User>(entity));
        }