예제 #1
0
        public ActionResult Create(HouseCreateViewModel houseCreateViewModel, HttpPostedFileBase ImageUpload)
        {
            if (ModelState.IsValid)
            {
                House house = new House
               {
                   Address = houseCreateViewModel.Address,
                   ReceiverIp = houseCreateViewModel.ReceiverIp,
                   DateCreate = houseCreateViewModel.DateCreate,
                   MaxArraySizeSensors = houseCreateViewModel.MaxArraySizeSensors,
                   MaxArraySizeTermostats = houseCreateViewModel.MaxArraySizeTermostats,
                   MaxNumberPins = houseCreateViewModel.MaxNumberPins,
                   Name = houseCreateViewModel.Name,
                   SecretKey = houseCreateViewModel.SecretKey,
                   ServerIp = houseCreateViewModel.ServerIp,
                   ServerPort = houseCreateViewModel.ServerPort,
                   TimeToCheckTemp = houseCreateViewModel.TimeToCheckTemp,
                   TimeToSendTemp = houseCreateViewModel.TimeToSendTemp,
                   UserId = houseCreateViewModel.UserId
               };

                HouseRCModel houseRCModel = new HouseRCModel
                {
                    ServerIp = house.ServerIp,
                    ServerPort = house.ServerPort,
                    ReceiverIp = house.ReceiverIp,
                    TimeToCheckTemp = house.TimeToCheckTemp,
                    TimeToSendTemp = house.TimeToSendTemp,
                };
                if ((ImageUpload != null && ImageUpload.ContentLength > 0))
                {
                    var fileName = Path.GetFileName(ImageUpload.FileName);
                    var path = Path.Combine(Server.MapPath("~" + Settings.Default.HousesPathImages), fileName);
                    ImageUpload.SaveAs(path);
                    house.ImageUrl = Settings.Default.HousesPathImages + fileName;
                }
                else
                {
                    house.ImageUrl = Settings.Default.HousesPathImages + Settings.Default.DefaultHouseImage;
                }

                using (TransactionScope transaction = new TransactionScope())
                {
                    this.Data.Houses.Add(house);
                    this.Data.SaveChanges();

                    this.RemoteControl.SendHouseSettings(houseRCModel);
                    transaction.Complete();
                }

                return RedirectToAction("List");
            }

            houseCreateViewModel.Users = HelperClass.GetAllUsers(this.Data, null);
            return View(houseCreateViewModel);
        }
예제 #2
0
 public ViewResult Create()
 {
     HouseCreateViewModel houseCreateViewModel = new HouseCreateViewModel
     {
         DateCreate = DateTime.Now,
         ServerIp = Settings.Default.ServerIp,
         ServerPort = Settings.Default.ServerPort,
         ReceiverIp = Settings.Default.ReceiverIp,
         TimeToCheckTemp = Settings.Default.TimeToCheckTemp,
         TimeToSendTemp = Settings.Default.TimeToSendTemp,
         MaxArraySizeSensors = Settings.Default.MaxArraySizeSensors,
         MaxArraySizeTermostats = Settings.Default.MaxArraySizeTermostats,
         MaxNumberPins = Settings.Default.MaxNumberPins,
         Users = HelperClass.GetAllUsers(this.Data, null)
     };
     return View(houseCreateViewModel);
 }