Beispiel #1
0
        public int CreateSublet(FullSubletModel fsm)
        {
            try
            {
                SubletDataEntity sde = _mapper.ExtractDataEntity(fsm);
                SubletModel      sm  = new SubletModel(fsm.Email, fsm.Address, fsm.Description, fsm.ImageUrl, fsm.Price, fsm.Rating);

                var newSub = _context.Sublets.Add(sm);
                _context.SaveChanges();

                sde.SubletID = newSub.Entity.ID;
                fsm.ID       = newSub.Entity.ID;
                _context.SubletData.Add(sde);
                _context.SaveChanges();

                UpdateTags(fsm);
                CreateRoommates(fsm);

                SubletType esSublet = new SubletType
                {
                    ID          = fsm.ID,
                    Address     = fsm.Address,
                    Description = fsm.Description,
                    Tags        = fsm.Tags
                };
                _elastic.IndexSublet(esSublet);

                return(newSub.Entity.ID);
            }
            catch (DbUpdateException e)
            {
                throw new DbUpdateException("error", e);
            }
        }
Beispiel #2
0
        public double UpdateRating(int id, int rating)
        {
            SubletModel sm = GetSublet(id);

            sm.RatingNumber += 1;
            sm.RatingTotal  += rating;
            sm.Rating        = (double)sm.RatingTotal / sm.RatingNumber;

            _context.Sublets.Update(sm);
            _context.SaveChanges();
            return(sm.Rating);
        }
Beispiel #3
0
        public int UpdateSublet(int id, FullSubletModel fsm)
        {
            try
            {
                FullSubletModel oldFsm = GetFullSublet(id);
                fsm.Email = oldFsm.Email;
                fsm.ID    = oldFsm.ID;

                _mapper.FillNulls(oldFsm, fsm);

                SubletDataEntity sde   = _mapper.ExtractDataEntity(fsm);
                SubletModel      sm    = new SubletModel(fsm.Email, fsm.Address, fsm.Description, fsm.ImageUrl, fsm.Price, fsm.Rating);
                SubletModel      oldSm = _context.Sublets.Where(s => s.ID == id).FirstOrDefault();
                oldSm.Address     = sm.Address;
                oldSm.Description = sm.Description;
                oldSm.Price       = sm.Price;
                oldSm.Rating      = sm.Rating;
                oldSm.ImageUrl    = sm.ImageUrl;

                _context.Sublets.Update(oldSm);
                _context.SaveChanges();

                SubletDataEntity oldSde = _context.SubletData.Where(sd => sd.SubletID == id).FirstOrDefault();
                oldSde.SubletID    = id;
                oldSde.Email       = sde.Email;
                oldSde.IsFurnished = sde.IsFurnished;
                oldSde.Description = sde.Description;
                oldSde.OpenHouse   = sde.OpenHouse;

                _context.SubletData.Update(oldSde);
                _context.SaveChanges();


                UpdateTags(fsm);
                UpdateRoommates(fsm);
                SubletType esSublet = new SubletType
                {
                    ID          = fsm.ID,
                    Description = fsm.Description,
                    Address     = fsm.Address,
                    Tags        = fsm.Tags
                };

                _elastic.IndexSublet(esSublet);
                return(id);
            }
            catch (DbUpdateException e)
            {
                throw new DbUpdateException("error", e);
            }
        }
Beispiel #4
0
        public FullSubletModel Map(SubletModel model, SubletDataEntity entity, string[] tags, RoommateEntity[] roommates)
        {
            FullSubletModel fsm = new FullSubletModel(model.ID, model.Email, model.Address, model.Price)
            {
                Description = entity.Description,
                IsFurnished = entity.IsFurnished,
                Roommates   = roommates,
                OpenHouse   = entity.OpenHouse,
                Tags        = tags,
                ImageUrl    = model.ImageUrl,
                Rating      = model.Rating
            };

            return(fsm);
        }
Beispiel #5
0
        public FullSubletModel GetFullSublet(int id)
        {
            SubletModel      sm  = _context.Sublets.Where(s => s.ID == id).FirstOrDefault();
            SubletDataEntity sde = _context.SubletData.Where(sd => sd.SubletID == id && sd.Email.Equals(sm.Email)).FirstOrDefault();

            List <string> tags = (from t in _context.Tags
                                  join ti in _context.TagIndex on t.TagID equals ti.ID into t_ti
                                  from s in t_ti.DefaultIfEmpty()
                                  where t.SubletID == id
                                  select s.Tag).ToList();

            RoommateEntity[] roommates = _context.Roommates.Where(r => r.SubletID == id).ToArray();
            FullSubletModel  fsm       = _mapper.Map(sm, sde, tags.ToArray(), roommates);

            return(fsm);
        }
Beispiel #6
0
        public SubletModel GetSublet(int id)
        {
            SubletModel sr = _context.Sublets.Where(s => s.ID == id).FirstOrDefault();

            return(sr);
        }