public void SendHouseSettings(HouseRCModel houseRCModel)
 {
     this.Sender.SendMessageToReceiver(new
     {
         SetConfiguration = new
         {
             ServerIp = houseRCModel.ServerIp.Replace('.', ','),
             ServerPort=houseRCModel.ServerPort,
             TimeToCheckTemp = houseRCModel.TimeToCheckTemp,
             TimeToSendTemp = houseRCModel.TimeToSendTemp
         }
     }, houseRCModel.ReceiverIp);
 }
Example #2
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);
        }