Example #1
0
        public IHttpActionResult Get(int id)
        {
            using (var dbContext = new TestDbContext())
            {
                DateTime dateCurrent = DateTime.Now.Date;
                DateTime firstDayOfWeek = FirstDayOfWeek(dateCurrent);
                DateTime lastDayOfWeek = LastDayOfWeek(dateCurrent);
                var listWeeklyAvailability = dbContext.Weeklies
                    .Where(o => o.UserId == id && o.FirstDayOfWeek == firstDayOfWeek && o.LastDayOfWeek == lastDayOfWeek)
                    .Select(s => new WeeklyViewModel
                    {
                        Id = s.Id,
                        Sun = s.Sun,
                        SunSelected = s.SunSelected,
                        Mon = s.Mon,
                        MonSelected = s.MonSelected,
                        Tue = s.Tue,
                        TueSelected = s.TueSelected,
                        Wed = s.Wed,
                        WedSelected = s.WedSelected,
                        Thu = s.Thu,
                        ThuSelected = s.ThuSelected,
                        Fri = s.Fri,
                        FriSelected = s.FriSelected,
                        Sat = s.Sat,
                        SatSelected = s.SatSelected,
                        FirstDayOfWeek = s.FirstDayOfWeek.ToString(),
                        LastDayOfWeek = s.LastDayOfWeek.ToString(),
                        UserId = s.UserId,
                    }).ToList();

                AvailabilityViewModel weeklyViewModel;
                if (listWeeklyAvailability.Count > 0)
                {
                    weeklyViewModel = new AvailabilityViewModel
                    {
                        Id = 0,
                        UserId = listWeeklyAvailability[0].UserId,
                        ListWeeklyViewModels = listWeeklyAvailability
                    };

                }
                else
                {
                    weeklyViewModel = new AvailabilityViewModel
                    {
                        Id = 0,
                        UserId = 0,
                        ListWeeklyViewModels = GenerationWeeklyAvailabilitie(id)
                    };
                }
                var test = weeklyViewModel;
                return Ok(weeklyViewModel);
            }

        }
Example #2
0
 public IEnumerable<UserViewModel> Get()
 {
     using (var dbContext = new TestDbContext())
     {
         var data = dbContext.Customers.Select(s => new UserViewModel
         {
             Id = s.Id,
             Name = s.User.Name,
             Address = s.Address
         }).ToList();
         return data;
     }
 }
Example #3
0
        public IHttpActionResult Get(int id)
        {
            var city = "";
            var abbreviationName = "";
            var url = "http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:" + id + "|country: US";
            var client = new WebClient();
            var response = client.DownloadString(new Uri(url));
            var data = JsonConvert.DeserializeObject<GoogleApiViewModel>(response);
            if (data != null && data.results.Count > 0 && data.results[0].address_components.Count > 0) {
                        for (var i = 0; i < data.results[0].address_components.Count; i++) {
                            if (data.results[0].address_components[i].types.Count > 0) {
                                for (var j = 0; j < data.results[0].address_components[i].types.Count; j++) {
                                    if (data.results[0].address_components[i].types[j].Contains("locality")) {
                                        city = data.results[0].address_components[i].long_name;
                                    }
                                    if (data.results[0].address_components[i].types[j].Contains("administrative_area_level_1")) {
                                        abbreviationName = data.results[0].address_components[i].short_name;
                                    }
                                }
                            }
                        }
                    }      
            var state = new State();           
            using (var dbContext = new TestDbContext())
            {
                state = dbContext.States.FirstOrDefault(o => o.AbbreviationName == abbreviationName);
            }

            var location = new StateViewModel();
            if (state != null)
            {
                //data.StateId = state.Id;
                location = new StateViewModel
                {
                    Zip = id,
                    City = city,
                    State = state.Name,
                    StateId = state.Id
                };
            }
            else
            {
                location = new StateViewModel();
            }

            return Ok(location);
        }
Example #4
0
 public IHttpActionResult Get()
 {
     using (var dbContext = new TestDbContext())
     {
         var data = dbContext.States.Select(s => new StateLookup
         {
             Id = s.Id,
             Name = s.Name,
             Image = "/Content/favicon.png"
         }).ToList();
       
         var liststate = new ListState
         {
             List = data
         };
         return Ok(liststate);
     }
 }       
Example #5
0
        public IHttpActionResult Get(int id)
        {
            using (var dbContext = new TestDbContext())
            {
                Mapper.CreateMap<User, UserViewModel>()
                .ForMember(d => d.Address, opt => opt.Ignore())
                .AfterMap((s, d) =>
                {
                    d.Address = s.Customer.Address;
                });

                var item = dbContext.Users.FirstOrDefault(o => o.Id == id);
                if (item == null)
                {
                    return NotFound();
                }
                var userViewModel = Mapper.Map<UserViewModel>(item);
                return Ok(userViewModel);
            }            

        }         
Example #6
0
 public IHttpActionResult Post(AvailabilityViewModel item)
 {
     using (var dbContext = new TestDbContext())
     {
         Mapper.CreateMap<WeeklyViewModel, Weekly>()
         .ForMember(d => d.FirstDayOfWeek, o => o.Ignore())
         .ForMember(d => d.LastDayOfWeek, o => o.Ignore())
          .AfterMap((s, d) =>
          {
              d.FirstDayOfWeek = DateTime.Parse(s.FirstDayOfWeek);
              d.LastDayOfWeek = DateTime.Parse(s.LastDayOfWeek);
          });
         foreach (var data in item.ListWeeklyViewModels)
         {
             var weekly = Mapper.Map<WeeklyViewModel,Weekly>(data);
             weekly.UserId = item.UserId;
             dbContext.Weeklies.Add(weekly);
         }
         dbContext.SaveChanges();
         return Ok();
     }
 }
Example #7
0
        public IHttpActionResult Post(UserViewModel item)
        {
            using (var dbContext = new TestDbContext())
            {
                Mapper.CreateMap<User, UserViewModel>()
                .ForMember(d => d.Address, opt => opt.Ignore())
                .AfterMap((s, d) =>
                {
                    d.Address = s.Customer.Address;
                });

                User user = new User();
                user.Name = item.Name;
                user.Customer = new Customer { Address = item.Address };

                dbContext.Users.Add(user);
                dbContext.SaveChanges();

                var userViewModel = Mapper.Map<UserViewModel>(user);
                return Ok(userViewModel);
            }
        }
Example #8
0
        public void Delete(int id)
        {
            using (var dbContext = new TestDbContext())
            {
                DateTime dateCurrent = DateTime.Now.Date;
                DateTime firstDayOfWeek = FirstDayOfWeek(dateCurrent);
                DateTime lastDayOfWeek = LastDayOfWeek(dateCurrent);

                dbContext.Weeklies.RemoveRange(
                    dbContext.Weeklies.Where(
                        o => o.UserId == id && o.FirstDayOfWeek == firstDayOfWeek && o.LastDayOfWeek == lastDayOfWeek));
                dbContext.SaveChanges();
            }
        }
Example #9
0
        public int Put(int id, AvailabilityViewModel item)
        {
            using (var dbContext = new TestDbContext())
            {
                DateTime dateCurrent = DateTime.Now.Date;
                DateTime firstDayOfWeek = FirstDayOfWeek(dateCurrent);
                DateTime lastDayOfWeek = LastDayOfWeek(dateCurrent);

                dbContext.Weeklies.RemoveRange(
                    dbContext.Weeklies.Where(
                        o => o.UserId == id && o.FirstDayOfWeek == firstDayOfWeek && o.LastDayOfWeek == lastDayOfWeek));
                #region
                //var listOldWeekly = dbContext.Weeklies
                //    .Where(o => o.UserId == id && o.FirstDayOfWeek == firstDayOfWeek && o.LastDayOfWeek == lastDayOfWeek)
                //    .Select(s => new WeeklyViewModel
                //    {
                //        Id = s.Id,
                //        Sun = s.Sun,
                //        SunSelected = s.SunSelected,
                //        Mon = s.Mon,
                //        MonSelected = s.MonSelected,
                //        Tue = s.Tue,
                //        TueSelected = s.TueSelected,
                //        Wed = s.Wed,
                //        WedSelected = s.WedSelected,
                //        Thu = s.Thu,
                //        ThuSelected = s.ThuSelected,
                //        Fri = s.Fri,
                //        FriSelected = s.FriSelected,
                //        Sat = s.Sat,
                //        SatSelected = s.SatSelected,
                //        UserId = s.UserId,
                //    }).ToList();

                //if (listOldWeekly.Count > 0)
                //{
                //    foreach (var data in listOldWeekly)
                //    {
                //        var weekly = new Weekly();
                //        weekly.Sun = data.Sun;
                //        weekly.SunSelected = data.SunSelected;
                //        weekly.Mon = data.Mon;
                //        weekly.MonSelected = data.MonSelected;
                //        weekly.Tue = data.Tue;
                //        weekly.TueSelected = data.TueSelected;
                //        weekly.Wed = data.Wed;
                //        weekly.WedSelected = data.WedSelected;
                //        weekly.Thu = data.Thu;
                //        weekly.ThuSelected = data.ThuSelected;
                //        weekly.Fri = data.Fri;
                //        weekly.FriSelected = data.FriSelected;
                //        weekly.Sat = data.Sat;
                //        weekly.SatSelected = data.SatSelected;
                //        weekly.FirstDayOfWeek = DateTime.Parse(data.FirstDayOfWeek);
                //        weekly.LastDayOfWeek = DateTime.Parse(data.LastDayOfWeek);
                //        weekly.UserId = data.UserId;
                //        dbContext.Weeklies.Add(weekly);
                //    }
                //}
                #endregion


                Mapper.CreateMap<WeeklyViewModel, Weekly>()
                .ForMember(d => d.FirstDayOfWeek, o => o.Ignore())
                .ForMember(d => d.LastDayOfWeek, o => o.Ignore())
                 .AfterMap((s, d) =>
                 {
                     d.FirstDayOfWeek = DateTime.Parse(s.FirstDayOfWeek);
                     d.LastDayOfWeek = DateTime.Parse(s.LastDayOfWeek);
                 });

                foreach (var data in item.ListWeeklyViewModels)
                {                   
                    var weekly = Mapper.Map<WeeklyViewModel, Weekly>(data);
                    weekly.UserId = item.UserId;
                    dbContext.Weeklies.Add(weekly);
                }
                dbContext.SaveChanges();
                return id;
            }
        }
Example #10
0
 public MilestoneRepository()
 {
     _context = new TestDbContext();
 }
Example #11
0
 public DatabaseVersionRepository()
 {
     _context = new TestDbContext();
 }
Example #12
0
        public int Put(int id, UserViewModel item)
        {
            item.Id = id;
            using (var dbContext = new TestDbContext())
            {
                var user = dbContext.Users.FirstOrDefault(o => o.Id == id);
                if (user == null)
                {
                    return 0;
                }

                user.Name = item.Name;
                user.Customer.Address = item.Address;
                dbContext.SaveChanges();

                return user.Id;
            }
        }
Example #13
0
 public void Delete(int id)
 {
     using (var dbContext = new TestDbContext())
     {
         var user = dbContext.Users.FirstOrDefault(o => o.Id == id);
         if (user == null)
         {
             throw new HttpResponseException(HttpStatusCode.NotFound);
         }
         dbContext.Users.Remove(user);
         dbContext.SaveChanges();
     }
 }