public ActionResult Create(RegisterSMSModel model, string[] CodeObservation)
        {
            string listCode = "";
            int    i        = 1;

            foreach (var item in CodeObservation)
            {
                if (i == 1)
                {
                    listCode = listCode + item.Trim();
                }
                else
                {
                    listCode = listCode + "," + item.Trim();
                }
                i++;
            }
            if (ModelState.IsValid)
            {
                RegisterSMS pts           = new RegisterSMS();
                bool        checkSave     = false;
                int         CurrentUserId = WebMatrix.WebData.WebSecurity.CurrentUserId;
                pts = model.ToEntity(pts);
                pts.CodeObservation       = listCode;
                pts.DateCreate            = DateTime.Now;
                checkSave                 = registerSMSService.registerResponsitory.Insert(pts);
                TempData["MessageStatus"] = checkSave;
                TempData["Message"]       = $"Thêm mới đăng ký nhận tin {(checkSave ? "" : "không")} thành công";
                return(RedirectToAction("index"));
            }
            return(View(model));
        }
        public ActionResult Update(RegisterSMSModel model, string[] CodeObservation)
        {
            if (ModelState.IsValid)
            {
                int    i        = 1;
                string listCode = "";
                foreach (var item in CodeObservation)
                {
                    if (i == 1)
                    {
                        listCode = listCode + item.Trim();
                    }
                    else
                    {
                        listCode = listCode + "," + item.Trim();
                    }
                    i++;
                }
                RegisterSMS pts = registerSMSService.registerResponsitory.Single(model.Id);
                if (pts == null)
                {
                    return(RedirectToAction("index"));
                }
                bool checkSave = false;
                pts = model.ToEntity(pts);
                pts.CodeObservation       = listCode;
                checkSave                 = registerSMSService.registerResponsitory.Update(pts);
                TempData["MessageStatus"] = checkSave;
                TempData["Message"]       = $"Cập nhật đăng ký nhận tin {(checkSave ? "" : "không")} thành công";

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Пример #3
0
 public static RegisterSMSModel ToModel(this RegisterSMS entity)
 {
     return(new RegisterSMSModel()
     {
         Id = entity.Id,
         DanhSachSDT = entity.DanhSachSDT,
         CodeObservation = entity.CodeObservation,
         DeviceId = entity.DeviceId,
         DateCreate = entity.DateCreate,
         GroupId = entity.GroupId,
         SMSServerId = entity.SMSServerId,
     });
 }
        public ActionResult Delete(int Id)
        {
            RegisterSMS pts         = registerSMSService.registerResponsitory.Single(Id);
            bool        checkDelete = false;

            if (pts != null)
            {
                checkDelete = registerSMSService.registerResponsitory.Delete(pts);
            }
            TempData["MessageStatus"] = checkDelete;
            TempData["Message"]       = $"Xóa đăng ký nhận tin {(checkDelete ? "" : "không")} thành công";
            return(RedirectToAction("Index", new { page = Request.Params["page"], pageSize = Request.Params["pageSize"], areaId = Request.Params["areaId"] }));
        }
        public ActionResult DeleteSelected(List <int> ids)
        {
            bool checkDelete = false;

            foreach (var i in ids)
            {
                RegisterSMS pts = registerSMSService.registerResponsitory.Single(i);
                if (pts != null)
                {
                    checkDelete = registerSMSService.registerResponsitory.Delete(pts);
                }
            }
            TempData["MessageStatus"] = checkDelete;
            TempData["Message"]       = $"Xóa đăng ký nhận tin {(checkDelete ? "" : "không")} thành công";
            return(Json(new { Result = checkDelete }));
        }
        public ActionResult Update(int id = 0)
        {
            CMSHelper help = new CMSHelper();

            @ViewBag.Title         = "";
            @ViewBag.MessageStatus = TempData["MessageStatus"];
            @ViewBag.Message       = TempData["Message"];
            int          CurrentUserId = WebMatrix.WebData.WebSecurity.CurrentUserId;
            string       userName      = User.Identity.Name;
            List <Site>  sites         = new List <Site>();
            List <Group> groups        = new List <Group>();

            if (userName == "administrator")
            {
                groups = groupService.groupResponsitory.GetAll().ToList();
                sites  = sitesService.sitesResponsitory.GetAll().ToList();
            }
            else
            {
                int   groupId = userProfileService.userProfileResponsitory.Single(CurrentUserId).Group_Id.Value;
                Group group   = groupService.groupResponsitory.Single(groupId);
                sites = sitesService.GetBygroupId(groupId).ToList();
                groups.Add(group);
            }
            RegisterSMS pts = registerSMSService.registerResponsitory.Single(id);

            if (pts == null)
            {
                return(RedirectToAction("index"));
            }
            ViewBag.listGroup       = groups;
            ViewBag.listObservation = observationService.observationResponsitory.GetAll();
            ViewBag.listSite        = sites;
            ViewBag.listSmsServer   = sMSServerService.smsServerResponsitory.GetAll();
            RegisterSMSModel model = pts.ToModel();

            return(View(model));
        }
Пример #7
0
 public static RegisterSMS ToEntity(this RegisterSMSModel model, RegisterSMS source = null)
 {
     if (source == null)
     {
         source = new RegisterSMS
         {
             Id              = source.Id,
             DanhSachSDT     = source.DanhSachSDT,
             CodeObservation = source.CodeObservation,
             DeviceId        = source.DeviceId,
             DateCreate      = source.DateCreate,
             GroupId         = source.GroupId,
             SMSServerId     = source.SMSServerId,
         };
     }
     source.Id              = model.Id;
     source.DanhSachSDT     = model.DanhSachSDT;
     source.CodeObservation = model.CodeObservation;
     source.DeviceId        = model.DeviceId;
     source.DateCreate      = model.DateCreate;
     source.GroupId         = model.GroupId;
     source.SMSServerId     = model.SMSServerId;
     return(source);
 }