Пример #1
0
        public async Task<IHttpActionResult> GetSalonsRealAdmin(int id, Salon salon)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var salonFromDb = await db.Salons.FindAsync(id);

            if (salonFromDb != null)
            {
                salonFromDb.AdminMessage = salon.AdminMessage;

                await db.SaveChangesAsync();
            }
            else
            {
                return NotFound();
            }

            return Ok();
        }
Пример #2
0
        public async Task<IHttpActionResult> PostSalon(SalonForUpdate salon)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Salon newSalon = new Salon();
            newSalon.AddedOn = DateTime.Now;
            newSalon.Address = new Address();
            newSalon.Address.AddressType = 2;
            newSalon.Address.Apartment = salon.SalonApartment;
            newSalon.Address.CityID = salon.CityID;
            newSalon.Address.Entrance = salon.SalonEntrance;
            newSalon.Address.Flat = salon.SalonFlat;
            newSalon.Address.NeighbourhoodID = salon.NeighbourhoodID;
            newSalon.Address.Number = salon.SalonNumber;
            newSalon.Address.Street = salon.SalonStreet;
            newSalon.CompanyID = await db.Companies.Where(x => x.CreateBy.ToUpper() == salon.Username)
                .Select(x => x.CompanyID).FirstOrDefaultAsync();
            newSalon.CreateBy = salon.Username;
            newSalon.Description = salon.SalonDescription;
            newSalon.SalonName = salon.SalonName;
            newSalon.SiteUrl = salon.SiteUrl;
            newSalon.VisibleForUsers = salon.VisibleForUsers;
            newSalon.IsDeleted = false;

            List<Email> emails = new List<Email>();
            emails.Add(new Email
            {
                Email1 = salon.Email
            });
            newSalon.Emails = emails;
            string[] phones = salon.SalonPhones.Split(',');
            List<Phone> itemsToAdd = phones.Select(x => new Phone
            {
                Phone1 = x
            }).ToList();

            newSalon.Phones = itemsToAdd;

            List<SalonSchedule> schedulesToAdd = new List<SalonSchedule>();
            foreach (var day in salon.SalonSchedule)
            {
                schedulesToAdd.Add(new SalonSchedule
                {
                    DayOfWeek = day.DayOfWeek,
                    EndTime = day.EndTime,
                    StartTime = day.StartTime,
                    Holiday = day.Holiday
                });
            }

            newSalon.SalonSchedules = schedulesToAdd;

            db.Salons.Add(newSalon);
            await db.SaveChangesAsync();

            List<Salon> salonForReturn = new List<Salon>();
            salonForReturn.Add(newSalon);

            var salonForRet = salonForReturn.Select(x => new
            {
                SalonID = x.SalonID,
                SalonName = x.SalonName,
                CityID = x.Address.CityID,
                NeighbourhoodID = x.Address.NeighbourhoodID,
                Neighbourhoods = db.Neighbourhoods.Where(z => z.CityID == x.Address.CityID).Select(z => new
                {
                    NeighbourhoodID = z.NeighbourhoodID,
                    NeighbourhoodName = z.NeighbourhoodName
                }),
                SalonStreet = x.Address.Street,
                SalonFlat = x.Address.Flat,
                SalonEntrance = x.Address.Entrance,
                SalonNumber = x.Address.Number,
                SalonApartment = x.Address.Apartment,
                SiteUrl = x.SiteUrl,
                Email = x.Emails.Where(z => z.SalonID == x.SalonID).Select(z => z.Email1).FirstOrDefault(),
                SalonDescription = x.Description,
                VisibleForUsers = x.VisibleForUsers,
                SalonPhones = x.Phones.Select(z => z.Phone1),
                SalonSchedule = x.SalonSchedules.Where(z =>
                !z.Date.HasValue).Select(z => new
                {
                    Date = z.Date,
                    DayOfWeek = z.DayOfWeek,
                    EndTime = z.EndTime,
                    StartTime = z.StartTime,
                    Holiday = z.Holiday,
                    SalonID = z.SalonID,
                    ScheduleID = z.ScheduleID
                }).OrderBy(z => z.DayOfWeek),
                SalonImages = x.SalonImages.Where(z => !z.IsDeleted).Select(z => new
                {
                    ImageID = z.ImageID,
                    ImagePath = z.ImagePath,
                    ImageName = z.ImageName,
                    IsMain = z.IsMain
                })
            }).FirstOrDefault();

            return CreatedAtRoute("DefaultApi", new { id = newSalon.SalonID }, salonForRet);
        }