Esempio n. 1
0
        public ActionResult Index()
        {
            ViewBag.FabricaAtivo        = "active";
            ViewBag.FabricaGatewayAtivo = "active";
            ViewBag.FabricaShow         = "show";

            List <Gateway>      lista_gateways      = new List <Gateway>();
            List <GatewayModel> lista_gateway_model = new List <GatewayModel>();

            //
            if (Codigo_Empresa > 0)
            {
                lista_gateways = db.Gateway.Where(a => a.Id_Empresa == Codigo_Empresa).ToList();
                //
                foreach (Gateway item in lista_gateways)
                {
                    GatewayModel gm = new GatewayModel();
                    //
                    gm.Id         = item.Id;
                    gm.Id_Empresa = Codigo_Empresa;
                    //
                    gm.Ativa     = item.Ativo;
                    gm.Descricao = item.Descricao;
                    gm.MAC       = item.MAC;
                    //
                    lista_gateway_model.Add(gm);
                }
            }
            //
            ViewBag.ListaGateways = lista_gateway_model;
            //
            return(View());
        }
Esempio n. 2
0
        public async Task <ActionResult> Edit(SMTPGatewayModel smtpgateway)
        {
            var GatewayModel = new GatewayModel
            {
                GatewayId      = smtpgateway.GatewayId,
                GatewayTypeId  = smtpgateway.GatewayTypeId,
                GatewayName    = smtpgateway.GatewayName,
                IsActive       = smtpgateway.IsActive,
                IsDefault      = smtpgateway.IsDefault,
                IsProcessByAWS = smtpgateway.IsProcessByAWS,
                Name           = smtpgateway.Name,
                Email          = smtpgateway.Email,
                SmtpServerName = smtpgateway.SmtpServerName,
                SmtpUserName   = smtpgateway.SmtpUserName,
                SmtpPassword   = smtpgateway.SmtpPassword,
                PortNumber     = smtpgateway.PortNumber,
                SSLEnabled     = smtpgateway.SSLEnabled,
                UserId         = CurrentUser.UserId,
                CompanyId      = CurrentUser.CompanyId
            };

            if (CurrentUser.UserTypeName.ToLower() == "super admin")
            {
                GatewayModel.CompanyId = smtpgateway.CompanyId;
            }
            var response = await _gatewayRepo.AddUpdateDeleteGateway(GatewayModel, 'U');

            _gatewayRepo.Save();
            TempData["response"] = response;

            return(RedirectToAction("Index"));
        }
        public ActionResult ManageGateway(string GatewayID = "")
        {
            GatewayCommon gatewaycommon = new GatewayCommon();
            GatewayModel  gatewaymodel  = new GatewayModel();

            if (!string.IsNullOrEmpty(GatewayID))
            {
                string gateway_id = GatewayID.DecryptParameter();
                if (!string.IsNullOrEmpty(gateway_id))
                {
                    gatewaycommon                    = buss.GetGatewayById(gateway_id);
                    gatewaymodel.GatewayId           = gatewaycommon.GatewayId.EncryptParameter();
                    gatewaymodel.GatewayName         = gatewaycommon.GatewayName;
                    gatewaymodel.GatewayUsername     = gatewaycommon.GatewayUsername.DecryptParameter();
                    gatewaymodel.GatewayPwd          = gatewaycommon.GatewayPwd.DecryptParameter();
                    gatewaymodel.GatewayBalance      = gatewaycommon.GatewayBalance;
                    gatewaymodel.GatewayURL          = gatewaycommon.GatewayURL.DecryptParameter();
                    gatewaymodel.GatewayAccessCode   = gatewaycommon.GatewayAccessCode.DecryptParameter();
                    gatewaymodel.GatewaySecurityCode = gatewaycommon.GatewaySecurityCode.DecryptParameter();
                    gatewaymodel.GatewayApitoken     = gatewaycommon.GatewayApitoken.DecryptParameter();
                    gatewaymodel.GatewayStatus       = gatewaycommon.GatewayStatus;
                    gatewaymodel.IsDirectGateway     = gatewaycommon.IsDirectGateway;
                    gatewaymodel.GatewayType         = gatewaycommon.GatewayType;
                    gatewaymodel.GatewayCountry      = gatewaycommon.GatewayCountry;
                    gatewaymodel.GatewayCurrency     = "NPR";//gatewaycommon.GatewayCurrency;
                    gatewaymodel.GatewayContact      = gatewaycommon.GatewayContact;
                }
            }
            gatewaymodel.GatewayCurrency     = "NPR";
            gatewaymodel.IsDirectGatewayList = LoadDropdownList("directindirect") as List <SelectListItem>;
            gatewaymodel.GatewayTypeList     = LoadDropdownList("gatewaytype") as List <SelectListItem>;
            // gatewaymodel.GatewayCurrencyList = ApplicationUtilities.SetDDLValue(ICB.sproc_get_dropdown_list("20"), gatewaymodel.GatewayCurrency, "Select Currency");
            gatewaymodel.GatewayCountryList = ApplicationUtilities.SetDDLValue(ICB.sproc_get_dropdown_list("030"), gatewaymodel.GatewayCurrency, "Select Country");
            return(View(gatewaymodel));
        }
Esempio n. 4
0
        public async Task <ActionResult> Create(SMTPGatewayModel smtpgateway)
        {
            var Gatewaylist = await CommonModel.GetGatewayType();

            var GatewayTypeId = Gatewaylist.Where(x => x.Text == "SMTP Gateway").Select(x => x.Value).SingleOrDefault();
            var GatewayModel  = new GatewayModel
            {
                GatewayId      = smtpgateway.GatewayId,
                GatewayTypeId  = GatewayTypeId,
                GatewayName    = smtpgateway.GatewayName,
                IsActive       = smtpgateway.IsActive,
                IsDefault      = smtpgateway.IsDefault,
                IsProcessByAWS = smtpgateway.IsProcessByAWS,
                Name           = smtpgateway.Name,
                Email          = smtpgateway.Email,
                SmtpServerName = smtpgateway.SmtpServerName,
                SmtpUserName   = smtpgateway.SmtpUserName,
                SmtpPassword   = smtpgateway.SmtpPassword,
                PortNumber     = smtpgateway.PortNumber,
                SSLEnabled     = smtpgateway.SSLEnabled,
                UserId         = CurrentUser.UserId,
                CompanyId      = CurrentUser.CompanyId
            };

            if (CurrentUser.UserTypeName.ToLower() == "super admin")
            {
                GatewayModel.CompanyId = smtpgateway.CompanyId;
            }
            var response = await _gatewayRepo.AddUpdateDeleteGateway(GatewayModel, 'I');

            _gatewayRepo.Save();
            TempData["response"] = response;
            TempData.Keep("response");
            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public JsonResult GetNearbyGateways(string deviceId, double radius = 200)
        {
            GatewayModel        gateway = Get(deviceId);
            List <GatewayModel> devices = GatewayModel.GetAllDevice();
            List <GatewayModel> res     = new List <GatewayModel>();

            double xx1, yy1;

            double.TryParse(gateway.LON, out xx1);
            double.TryParse(gateway.LAT, out yy1);

            foreach (var device in devices)
            {
                double xx2, yy2;
                if (double.TryParse(device.LON, out xx2) && double.TryParse(device.LAT, out yy2))
                {
                    if (Distance.GetDistance("baidu", yy2, xx2, yy1, xx1) <= radius && device.DeviceId.ToLower() != deviceId.ToLower())
                    {
                        res.Add(device);
                    }
                }
            }

            return(Json(new { Center = gateway, Nearby = res }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        public GatewaySerializer GetGatewayById(int id)
        {
            GatewayModel      gateway = this._gatewayDao.GetById(id);
            GatewaySerializer result  = new GatewaySerializer(gateway);

            return(result);
        }
Esempio n. 7
0
        public JsonResult GetPathway(string numbers, DateTime timeIntervalsBegin, DateTime timeIntervalsEnd)
        {
            var res = new List <PathwayModel>();

            string[] nums  = numbers.Trim().Split(',');
            int      count = nums.Length;

            var pathData    = PathDataModel.GetAllPathData();
            var gatewayData = GatewayModel.GetAllDevice();

            for (int i = 0; i < count; i++)
            {
                var pathway = new PathwayModel();
                pathway.Number   = nums[i];
                pathway.Gateways = new List <GatewayPathModel>();

                var pData = pathData.Where(x => x.Number == nums[i] && x.Time >= timeIntervalsBegin && x.Time <= timeIntervalsEnd).OrderBy(x => x.Time).ToList();
                foreach (var item in pData)
                {
                    var gateway = GatewayController.Get(item.DeviceId);
                    GatewayPathModel gatewayPath = new GatewayPathModel(gateway.DeviceId, gateway.LAT, gateway.LON, gateway.Address, item.Time);
                    pathway.Gateways.Add(gatewayPath);
                }
                if (pathway.Gateways.Count > 0)
                {
                    res.Add(pathway);
                }
            }

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
 public async Task AddGateway(GatewayModel model)
 {
     if (!ValidateIpv4(model.Ipv4))
     {
         throw new InvalidIpv4Exception();
     }
     var entity = Mapper.Map <DatGateway>(model);
     await _service.CreateAsync(entity);
 }
        public IActionResult gateWayRegister([FromBody] GatewayModel gatewayInfo)
        {
            gatewayInfo.UpdateTime = DateTime.Now;
            bool result = _gatewayControl.gatewayRegister(gatewayInfo);

            return(new OkObjectResult(new CloudResponseModel {
                messageType = (int)messageCode.gateWayCode.registerResponse, content = result.ToString()
            }));
        }
Esempio n. 10
0
        private ReponseViewModel SendSms(TemplateModel template, GatewayModel gatway)
        {
            var    respose = new ReponseViewModel();
            string authKey = gatway.OTPApikey;
            //Multiple mobiles numbers separated by comma
            string mobileNumber = template.PhoneNumber;
            //Sender ID,While using route4 sender id should be 6 characters long.
            string senderId = gatway.SenderID;

            template.MessageText = template.EmailBody;
            //Your message to send, Add URL encoding here.
            string message = Regex.Replace(template.MessageText, "<.*?>", string.Empty);

            message = Regex.Replace(message, "&nbsp;", " ");

            //Prepare you post parameters
            StringBuilder sbPostData = new StringBuilder();

            sbPostData.AppendFormat("authkey={0}", authKey);
            sbPostData.AppendFormat("&to={0}", mobileNumber);
            sbPostData.AppendFormat("&message={0}", message);
            sbPostData.AppendFormat("&route={0}", "default");
            try
            {
                //Call Send SMS API
                string sendSMSUri = gatway.URL;
                //Create HTTPWebrequest
                HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(sendSMSUri);
                //Prepare and Add URL Encoded data
                UTF8Encoding encoding = new UTF8Encoding();
                byte[]       data     = encoding.GetBytes(sbPostData.ToString());
                //Specify post method
                httpWReq.Method        = "POST";
                httpWReq.ContentType   = "application/x-www-form-urlencoded";
                httpWReq.ContentLength = data.Length;
                using (Stream stream = httpWReq.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
                //Get the response
                HttpWebResponse response       = (HttpWebResponse)httpWReq.GetResponse();
                StreamReader    reader         = new StreamReader(response.GetResponseStream());
                var             responseString = reader.ReadToEnd();
                //Close the response
                reader.Close();
                response.Close();
                var res = JsonConvert.DeserializeObject <ReponseViewModel>(responseString);
                return(res);
            }
            catch (SystemException ex)
            {
                return(new ReponseViewModel {
                    Status = "Faild", Message = ex.Message
                });
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Create gateway event
 /// </summary>
 /// <param name="type"></param>
 /// <param name="context"></param>
 /// <param name="gatewayId"></param>
 /// <param name="gateway"></param>
 /// <returns></returns>
 private static GatewayEventModel Wrap(GatewayEventType type,
                                       RegistryOperationContextModel context, string gatewayId,
                                       GatewayModel gateway)
 {
     return(new GatewayEventModel {
         EventType = type,
         Context = context,
         Id = gatewayId,
         Gateway = gateway
     });
 }
        public async Task UpdateGateway(long id, GatewayModel model)
        {
            var entity = await _service.GetByIdAsync(id);

            if (entity == null)
            {
                throw new NotFoundException(Constants.Resources.Gateway);
            }
            Mapper.Map(model, entity);
            await _service.UpdateAsync(entity);
        }
Esempio n. 13
0
        public JsonResult GetGateway(string ids)
        {
            List <GatewayModel> list = new List <GatewayModel>();

            string[] deviceIds = ids.Trim().Split(',');
            foreach (var id in deviceIds)
            {
                GatewayModel model = Get(id);
                list.Add(model);
            }
            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Esempio n. 14
0
 /// <summary>
 /// Create api model
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static GatewayApiModel ToApiModel(
     this GatewayModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new GatewayApiModel {
         Id = model.Id,
         SiteId = model.SiteId,
         Connected = model.Connected
     });
 }
Esempio n. 15
0
        public string Send(MessageRequestModel message, GatewayModel gateway)
        {
            var serviceUrl = gateway.ServiceUrl
                             .Replace("#username", gateway.Username)
                             .Replace("#password", gateway.Password)
                             .Replace("#from", message.From)
                             .Replace("#to", message.To)
                             .Replace("#subject", message.Subject)
                             .Replace("#message", message.Message)
                             .Replace("#brand", message.Brand);

            return(XNotifiRequest.Send(serviceUrl));
        }
Esempio n. 16
0
        public ValidationResult ValidateUpdate(GatewayModel model)
        {
            this.validationResult = new ValidationResult();

            if (model == null)
            {
                this.validationResult.AddErrorMessage(ResourceDesignation.Invalid_Designation);
                return(this.validationResult);
            }

            this.ValidateName(model.Provider);

            return(this.validationResult);
        }
Esempio n. 17
0
        public String CreateNewGateway(GatewaySerializer gatewaySerializer)
        {
            GatewayModel gatewayModel = new GatewayModel();

            gatewayModel.HardwareGatewayId = gatewaySerializer.hardwareGatewayID;
            gatewayModel.GatewayName       = gatewaySerializer.gatewayName;
            gatewayModel.City         = gatewaySerializer.city;
            gatewayModel.Factory      = gatewaySerializer.factory;
            gatewayModel.Workshop     = gatewaySerializer.workshop;
            gatewayModel.GatewayType  = gatewaySerializer.gatewayType;
            gatewayModel.GatewayState = gatewaySerializer.gatewayState;
            gatewayModel.ImageUrl     = gatewaySerializer.imageUrl;
            gatewayModel.Remark       = gatewaySerializer.remark;
            return(this._gatewayDao.Create(gatewayModel));
        }
Esempio n. 18
0
 public String Create(DeviceModel deviceModel)
 {
     using (var connection = new MySqlConnection(Constant.getDatabaseConnectionString()))
     {
         CityModel city = connection.Query <CityModel>(
             "SELECT * FROM city WHERE city.cityName=@cn", new
         {
             cn = deviceModel.City
         }).FirstOrDefault();
         FactoryModel factory = connection.Query <FactoryModel>(
             "SELECT * FROM factory WHERE factory.factoryName=@fn", new
         {
             fn = deviceModel.Factory
         }).FirstOrDefault();
         WorkshopModel workshop = connection.Query <WorkshopModel>(
             "SELECT * FROM workshop WHERE workshop.workshopName=@wn", new
         {
             wn = deviceModel.Workshop
         }).FirstOrDefault();
         GatewayModel gateway = connection.Query <GatewayModel>("select * from gateway where gatewayName=@gn",
                                                                new { gn = deviceModel.GatewayId }).FirstOrDefault();
         int deviceType = connection.Query <int>(
             "select id from config where configTag=@ct and configValue=@cv", new
         {
             ct = "deviceType",
             cv = deviceModel.DeviceType
         }).FirstOrDefault();
         int rows = connection.Execute(
             "INSERT INTO " +
             "device(hardwareDeviceID, deviceName, city, factory, workshop, deviceState, imageUrl, gatewayId, mac, deviceType, remark)" +
             " VALUES (@hdid, @dn, @c, @f, @w, @ds, @iu, @gid, @m, @dt, @r)", new
         {
             hdid = deviceModel.HardwareDeviceId,
             dn   = deviceModel.DeviceName,
             c    = city.Id,
             f    = factory.Id,
             w    = workshop.Id,
             ds   = deviceModel.DeviceState,
             iu   = deviceModel.ImageUrl,
             gid  = gateway.Id,
             m    = deviceModel.Mac,
             dt   = deviceType,
             r    = deviceModel.Remark
         });
         return(rows == 1 ? "success" : "error");
     }
 }
Esempio n. 19
0
 public GatewaySerializer(GatewayModel gatewayModel)
 {
     this.id = gatewayModel.Id;
     this.hardwareGatewayID = gatewayModel.HardwareGatewayId;
     this.gatewayName       = gatewayModel.GatewayName;
     this.city               = gatewayModel.City;
     this.factory            = gatewayModel.Factory;
     this.workshop           = gatewayModel.Workshop;
     this.gatewayType        = gatewayModel.GatewayType;
     this.gatewayState       = gatewayModel.GatewayState;
     this.imageUrl           = gatewayModel.ImageUrl;
     this.remark             = gatewayModel.Remark;
     this.lastConnectionTime = DateTime.Parse(gatewayModel.LastConnectionTime.ToString())
                               .ToLocalTime().ToString(Constant.getDateFormatString());
     this.createTime = DateTime.Parse(gatewayModel.CreateTime.ToString())
                       .ToLocalTime().ToString(Constant.getDateFormatString());
     this.updateTime = DateTime.Parse(gatewayModel.UpdateTime.ToString())
                       .ToLocalTime().ToString(Constant.getDateFormatString());
 }
Esempio n. 20
0
        public ActionResult ManageGateway(GatewayModel gm)
        {
            if (ModelState.IsValid)
            {
                string username  = Session["UserName"].ToString();
                string ipaddress = ApplicationUtilities.GetIP();

                GatewayCommon gc = new GatewayCommon();
                gc.GatewayId = gm.GatewayId.DecryptParameter();
                if (!string.IsNullOrEmpty(gc.GatewayId))
                {
                    if (string.IsNullOrEmpty(gm.GatewayId))
                    {
                        this.ShowPopup(1, "Gateway Not found !");
                        return(RedirectToAction("ManageGateway", gm));
                    }
                }
                gc.GatewayName     = gm.GatewayName;
                gc.GatewayUsername = gm.GatewayUsername.EncryptParameter();
                gc.GatewayPwd      = gm.GatewayPwd.EncryptParameter();
                // gc.GatewayBalance = gm.GatewayBalance;
                gc.GatewayURL          = gm.GatewayURL.EncryptParameter();
                gc.GatewayAccessCode   = gm.GatewayAccessCode.EncryptParameter();
                gc.GatewaySecurityCode = gm.GatewaySecurityCode.EncryptParameter();
                gc.GatewayApitoken     = gm.GatewayApitoken.EncryptParameter();
                gc.GatewayStatus       = gm.GatewayStatus;
                gc.IsDirectGateway     = gm.IsDirectGateway;
                gc.GatewayType         = gm.GatewayType.Trim();
                gc.GatewayCountry      = gm.GatewayCountry;
                gc.GatewayCurrency     = gm.GatewayCurrency;
                gc.GatewayContact      = gm.GatewayContact;
                gc.ActionUser          = username;
                gc.IpAddress           = ipaddress;
                CommonDbResponse dbresp = buss.ManageGateway(gc);
                if (dbresp.Code == 0)
                {
                    this.ShowPopup(0, "Save Succesfully");
                    return(RedirectToAction("Detail"));
                }
            }
            this.ShowPopup(1, "Error");
            return(RedirectToAction("ManageGateway", gm));
        }
Esempio n. 21
0
        public IActionResult Edit(GatewayModel model)
        {
            SelectList();
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                _gatewayService.Update(model);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }

            return(View(model));
        }
 public async Task <ActionResult> Create(NotificationGatewayModel notificationgateway)
 {
     if (ModelState.IsValid)
     {
         var gatewayModel = new GatewayModel
         {
             GatewayId         = notificationgateway.GatewayId,
             GatewayTypeId     = notificationgateway.GatewayTypeId,
             GatewayName       = notificationgateway.GatewayName,
             IsActive          = notificationgateway.IsActive,
             SenderID          = notificationgateway.SenderID,
             GoogleApikey      = notificationgateway.GoogleApikey,
             GoogleApiURL      = notificationgateway.GoogleApiUrl,
             GoogleProjectID   = notificationgateway.GoogleProjectID,
             GoogleProjectName = notificationgateway.GoogleProjectName,
             UserId            = CurrentUser.UserId,
             CompanyId         = CurrentUser.CompanyId,
         };
         if (CurrentUser.UserTypeName.ToLower() == "super admin")
         {
             gatewayModel.CompanyId = notificationgateway.CompanyId;
         }
         ResponseModel response = new ResponseModel();
         if (gatewayModel.GatewayId != 0)
         {
             response = await _gatewayRepo.AddUpdateDeleteGateway(gatewayModel, 'U');
         }
         else
         {
             response = await _gatewayRepo.AddUpdateDeleteGateway(gatewayModel, 'I');
         }
         _gatewayRepo.Save();
         TempData["response"] = response;
         TempData.Keep("response");
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(notificationgateway));
     }
 }
Esempio n. 23
0
        public Response <GatewayModel> Create(GatewayModel model)
        {
            try
            {
                var validationResult = _gatewayValidation.ValidateCreate(model);
                if (!validationResult.IsValid)
                {
                    return new Response <GatewayModel>
                           {
                               Message    = validationResult.ErrorMessage,
                               ResultType = ResultType.ValidationError
                           }
                }
                ;

                model.GatewayId   = _generator.GenerateGuid().Result;
                model.Password    = _generator.Encrypt(model.Password).Result;
                model.IsActive    = true;
                model.DateCreated = DateTime.UtcNow;

                _gatewayRepository.Insert(_mapper.Map <Gateway>(model));
                _gatewayRepository.Save();

                return(new Response <GatewayModel>
                {
                    Result = model,
                    ResultType = ResultType.Success
                });
            }
            catch (Exception ex)
            {
                //online error log
                var err = ex.Message;
            }

            return(new Response <GatewayModel>
            {
                ResultType = ResultType.Error
            });
        }
        public async Task PostSuccess(String hardwareGatewayId, String gatewayName, String city, String factory, String workshop, String gatewayType, String gatewayState, String imageUrl, String remark)
        {
            var data = new GatewayModel
            {
                HardwareGatewayId = hardwareGatewayId,
                GatewayName       = gatewayName,
                City         = city,
                Factory      = factory,
                Workshop     = workshop,
                GatewayType  = gatewayType,
                GatewayState = gatewayState,
                ImageUrl     = imageUrl,
                Remark       = remark
            };
            var content  = new StringContent(data.ToJson(), Encoding.UTF8, "text/json");
            var response = await this._httpClient.PostAsync("api/gateway", content);

            var result = response.Content.ReadAsStringAsync().Result;

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Contains("\"c\":200,\"m\":\"success\",\"d\":\"success\"", result);
        }
Esempio n. 25
0
        public JsonResult GetDrawGateway(decimal x1, decimal y1, decimal x2, decimal y2)
        {
            //所有网关
            List <GatewayModel> devices = GatewayModel.GetAllDevice();

            //在矩形区域内的网关
            List <GatewayModel> innerDevices = new List <GatewayModel>();

            for (int i = 0; i < devices.Count; i++)
            {
                decimal xx1, xx2, yy1, yy2;
                if (decimal.TryParse(devices[i].LON, out xx1) && decimal.TryParse(devices[i].LON, out xx2) && decimal.TryParse(devices[i].LAT, out yy1) && decimal.TryParse(devices[i].LAT, out yy2))
                {
                    if (xx1 >= x1 && xx2 <= x2 && yy1 >= y1 && yy2 <= y2)
                    {
                        innerDevices.Add(devices[i]);
                    }
                }
            }

            return(Json(innerDevices, JsonRequestBehavior.AllowGet));
        }
 public async Task <ActionResult> Create(SMSGatewayModel smsgateway)
 {
     if (ModelState.IsValid)
     {
         var gatewayModel = new GatewayModel {
             GatewayId      = smsgateway.GatewayId,
             GatewayTypeId  = smsgateway.GatewayTypeId,
             GatewayName    = smsgateway.GatewayName,
             IsActive       = smsgateway.IsActive,
             OTPApikey      = smsgateway.OTPApikey,
             TransApikey    = smsgateway.TransApikey,
             URL            = smsgateway.URL,
             OTPSender      = smsgateway.OTPSender,
             SuccessMessage = smsgateway.SuccessMessage,
             UserId         = CurrentUser.UserId,
             CompanyId      = CurrentUser.CompanyId
         };
         if (CurrentUser.UserTypeName.ToLower() == "super admin")
         {
             gatewayModel.CompanyId = smsgateway.CompanyId;
         }
         ResponseModel response = new ResponseModel();
         if (gatewayModel.GatewayId != 0)
         {
             response = await _gatewayRepo.AddUpdateDeleteGateway(gatewayModel, 'U');
         }
         else
         {
             response = await _gatewayRepo.AddUpdateDeleteGateway(gatewayModel, 'I');
         }
         _gatewayRepo.Save();
         TempData["response"] = response;
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(smsgateway));
     }
 }
Esempio n. 27
0
        public ReponseViewModel SendEmail(MailMessage mail, GatewayModel gateway)
        {
            var respose = new ReponseViewModel();

            SmtpClient smtp = new SmtpClient();

            smtp.Host = gateway.SmtpServerName;
            smtp.Port = Convert.ToInt32(gateway.PortNumber);
            smtp.UseDefaultCredentials = false;
            smtp.Credentials           = new System.Net.NetworkCredential(gateway.SmtpUserName, gateway.SmtpPassword);
            mail.From = new MailAddress(gateway.Email);
            try
            {
                smtp.Send(mail);
                respose.Status = "Success";
            }
            catch (Exception ex)
            {
                respose.Status  = "Failed";
                respose.Message = ex.Message;
            }
            return(respose);
        }
Esempio n. 28
0
        /// <summary>
        /// Create gateway instance if needed
        /// </summary>
        /// <returns></returns>
        public static async Task <GatewayModel> GetGateway()
        {
            if (_gateway == null)
            {
                var account = new AccountModel
                {
                    Name = "Options",
                    Id   = ConfigurationManager.AppSettings["Account"]
                };

                _gateway = new GatewayClient()
                {
                    Name         = "Options",
                    Account      = account,
                    LiveToken    = ConfigurationManager.AppSettings["TradierLiveToken"].ToString(),
                    SandboxToken = ConfigurationManager.AppSettings["TradierSandboxToken"].ToString()
                };

                await _gateway.Connect();
            }

            return(_gateway);
        }
Esempio n. 29
0
 public String Update(int id, GatewayModel gatewayModel)
 {
     using (var connection = new SqlConnection(Constant.getDatabaseConnectionString()))
     {
         CityModel city = connection.Query <CityModel>(
             "SELECT * FROM city WHERE city.cityName=@cn", new
         {
             cn = gatewayModel.City
         }).FirstOrDefault();
         FactoryModel factory = connection.Query <FactoryModel>(
             "SELECT * FROM factory WHERE factory.factoryName=@fn", new
         {
             fn = gatewayModel.Factory
         }).FirstOrDefault();
         WorkshopModel workshop = connection.Query <WorkshopModel>(
             "SELECT * FROM workshop WHERE workshop.workshopName=@wn", new
         {
             wn = gatewayModel.Workshop
         }).FirstOrDefault();
         int rows = connection.Execute(
             "UPDATE gateway SET hardwareGatewayID=@hgid, gatewayName=@gn, city=@c, factory=@f, workshop=@w, gatewayType=@gt, gatewayState=@gs, imageUrl=@iu, remark=@r, updateTime=CURRENT_TIMESTAMP WHERE id=@gatewayId",
             new
         {
             gatewayId = id,
             hgid      = gatewayModel.HardwareGatewayId,
             gn        = gatewayModel.GatewayName,
             c         = city.Id,
             f         = factory.Id,
             w         = workshop.Id,
             gt        = gatewayModel.GatewayType,
             gs        = gatewayModel.GatewayState,
             iu        = gatewayModel.ImageUrl,
             r         = gatewayModel.Remark
         });
         return(rows == 1 ? "success" : "error");
     }
 }
Esempio n. 30
0
 public String Create(GatewayModel gatewayModel)
 {
     using (var connection = new SqlConnection(Constant.getDatabaseConnectionString()))
     {
         CityModel city = connection.Query <CityModel>(
             "SELECT * FROM city WHERE city.cityName=@cn", new
         {
             cn = gatewayModel.City
         }).FirstOrDefault();
         FactoryModel factory = connection.Query <FactoryModel>(
             "SELECT * FROM factory WHERE factory.factoryName=@fn", new
         {
             fn = gatewayModel.Factory
         }).FirstOrDefault();
         WorkshopModel workshop = connection.Query <WorkshopModel>(
             "SELECT * FROM workshop WHERE workshop.workshopName=@wn", new
         {
             wn = gatewayModel.Workshop
         }).FirstOrDefault();
         int rows = connection.Execute(
             "INSERT INTO gateway(hardwareGatewayID, gatewayName, city, factory, workshop, gatewayType, gatewayState, imageUrl, remark)" +
             " VALUES(@hgid, @gn, @c, @f, @w, @gt, @gs, @iu, @r)", new
         {
             hgid = gatewayModel.HardwareGatewayId,
             gn   = gatewayModel.GatewayName,
             c    = city.Id,
             f    = factory.Id,
             w    = workshop.Id,
             gt   = gatewayModel.GatewayType,
             gs   = gatewayModel.GatewayState,
             iu   = gatewayModel.ImageUrl,
             r    = gatewayModel.Remark
         });
         return(rows == 1 ? "success" : "error");
     }
 }