예제 #1
0
        public ActionResult Edit([DataSourceRequest] DataSourceRequest request, users us)
        {
            if (ModelState.IsValid)
            {
                using (var db = new hercules_dbEntities())
                {
                    var result = from u in db.users where (u.Id == us.Id) select u;
                    if (result.Count() != 0)
                    {
                        var dbuser = result.First();

                        dbuser.FirstName = us.FirstName;
                        dbuser.LastName = us.LastName;
                        dbuser.Username = us.Username;
                        dbuser.Password = us.Password;
                        dbuser.Email = us.Email;
                        dbuser.Mobile = us.Mobile;
                        dbuser.Role = us.Role;
                        dbuser.RecieveNotifications = us.RecieveNotifications;
                        dbuser.Status = us.Status;

                        db.SaveChanges();
                    }
                }
            }

            return RedirectToAction("List");
        }
        private IEnumerable<dynamic> GetData()
        {
            var db = new hercules_dbEntities();

            var result = from a in db.loggers
                         join b in db.sites
                             on a.SiteID equals b.ID
                         join c in db.zones2
                             on b.ZoneID equals c.ID
                         join d in db.users
                              on a.OwnerAccount equals d.Id
                         select new
                         {
                             a.ID,
                             LoggerSMSNumber = a.LoggerSMSNumber,
                             BatteryLevel = a.BatteryLevel,
                             LastCallIn = a.LastCallIn,
                             Adress = a.Adress,
                             LoggerSerialNumber = a.LoggerSerialNumber,
                             LoggerType = a.LoggerType,
                             SignalLevel = a.SignalLevel,
                             Owner = d.FirstName + " " + d.LastName,
                             OwnerID = d.Id,
                             a.CreationDate,
                             SiteID = a.SiteID,
                             SiteName = b.Address,
                             ZoneID = c.ID,
                             ZoneName = c.ZoneName
                         };

            result = result.OrderBy(u => u.CreationDate);
            return result;
        }
예제 #3
0
        public ActionResult CreateLogger(zone zo)
        {
            if (ModelState.IsValid)
            {
                using (var northwind = new hercules_dbEntities())
                {
                    // Create a new Product entity and set its properties from the posted ProductViewModel
                    var entity = new zone
                    {

                        ZoneName = zo.ZoneName,
                        Status = true,
                        CreationDate = DateTime.Now

                    };
                    // Add the entity
                    northwind.zones2.Add(entity);
                    // Insert the entity in the database
                    northwind.SaveChanges();
                    // Get the ProductID generated by the database

                }

            }
            return Redirect("List");
        }
예제 #4
0
        public ActionResult Login(user u)
        {
            // this action is for handle post (login)
            if (ModelState.IsValid) // this is check validity
            {
            using (var mc = new hercules_dbEntities())
            {

                var vc = mc.company.Where(c => c.CompanyName.Equals(u.Email)).FirstOrDefault();
                if (vc != null)
                {
                    Session["CompanyID"] = vc.ID.ToString();
                    Session["CompanyName"] = vc.CompanyName.ToString();
                }
                else
                {
                    Session["CompanyID"] = null;
                    Session["CompanyName"] = null;
                }

            }

            using (hercules_dbEntities dc = new hercules_dbEntities())
            {
                if (Session["CompanyID"] != null) {
                    Int32 value_company_id = Convert.ToInt32(Session["CompanyID"].ToString());
                    var v = dc.users.Where(a => a.Username.Equals(u.Username) && a.Password.Equals(u.Password) && a.CompanyID.Equals(value_company_id)).FirstOrDefault();
                    if (v != null)
                    {
                        //Update the last connection by user
                        var update = from fu in dc.users where (fu.Id == v.Id) select fu;
                        if (update.Count() != 0) {
                        var dbuser = update.First();
                        dbuser.LastLogin = DateTime.Now;

                         dc.SaveChanges();
                         }

                        Session["LogedUserID"] = v.Id.ToString();
                        Session["LogedUserFullname"] = v.Username.ToString();
                        FormsAuthentication.SetAuthCookie(v.Username.ToString(), true);
                        return RedirectToAction("List","Dashboard");
                    }else
                        ModelState.AddModelError("", Resources.ResourceLanguage.UserInvalid);
                }else
                    ModelState.AddModelError("", Resources.ResourceLanguage.UserInvalid);
            }
            }
            return View(u);
        }
예제 #5
0
 //user - validation login
 public ActionResult UserValidation(string user)
 {
     using (hercules_dbEntities db = new hercules_dbEntities())
     {
         try
         {
             var tag = db.users.Single(m => m.Username == user);
             return Json(false, JsonRequestBehavior.AllowGet);
         }
         catch (Exception)
         {
             return Json(true, JsonRequestBehavior.AllowGet);
         }
     }
 }
예제 #6
0
        public ActionResult Create(loggers d)
        {
            if (ModelState.IsValid)
            {
                using (var northwind = new hercules_dbEntities())
                {
                    //Get max ID table loggers
                    var crum = northwind.loggers.Max(sd => sd.ID);

                    int current_id = Convert.ToInt32(crum.ToString());

                    // Create a new Product entity and set its properties from the posted ProductViewModel
                    var entity = new loggers
                    {

                        ID = current_id + 1,
                        LoggerSMSNumber = d.LoggerSMSNumber,
                        LoggerSerialNumber = d.LoggerSerialNumber,
                        Notes = d.Notes,
                        CreationDate = DateTime.Now,
                        Adress = d.Adress,
                        LatEast = d.LatEast,
                        LongNorth = d.LongNorth,
                        HeightAOD = d.HeightAOD,
                        LoggerTypeClass = d.LoggerTypeClass,
                        SiteID = d.SiteID,
                        OwnerAccount = Convert.ToInt16(Session["LogedUserID"].ToString()),
                        CompanyID = Convert.ToInt16(Session["CompanyID"].ToString()),
                        LoggerStatus = true

                    };
                    // Add the entity
                    northwind.loggers.Add(entity);
                    // Insert the entity in the database
                    northwind.SaveChanges();
                    // Get the ProductID generated by the database

                }

                return RedirectToAction("ListLogger");
                // return View();

            }
            else
            {
                return View();
            }
        }
예제 #7
0
        public ActionResult Delete([DataSourceRequest] DataSourceRequest request,loggers log)
        {
            using (var db = new hercules_dbEntities())
            {
                   var result = from u in db.loggers where (u.ID == log.ID) select u;
                    if (result.Count() != 0)
                    {
                        var dbuser = result.First();
                        dbuser.LoggerStatus = false;

                        db.SaveChanges();
                    }
            }

            return Json(new[] { log }.ToDataSourceResult(request, ModelState));
        }
예제 #8
0
        //Adress Site
        public ActionResult AdressValidation(string Address, string InitialAddess)
        {
            if (Address == InitialAddess)
                return Json(true, JsonRequestBehavior.AllowGet);

            using (hercules_dbEntities db = new hercules_dbEntities())
            {
                try
                {
                    var tag = db.sites.Single(m => m.Address == Address);
                    return Json(false, JsonRequestBehavior.AllowGet);
                }
                catch (Exception)
                {
                    return Json(true, JsonRequestBehavior.AllowGet);
                }
            }
        }
예제 #9
0
        //logger - sms
        public ActionResult LoggerValidation(string LoggerSMSNumber, string initialSMS)
        {
            if (LoggerSMSNumber == initialSMS)
                return Json(true, JsonRequestBehavior.AllowGet);

            using (hercules_dbEntities db = new hercules_dbEntities())
            {
                try
                {
                    var tag = db.loggers.Single(m => m.LoggerSMSNumber == LoggerSMSNumber);
                    return Json(false, JsonRequestBehavior.AllowGet);
                }
                catch (Exception)
                {
                    return Json(true, JsonRequestBehavior.AllowGet);
                }
            }
        }
예제 #10
0
        //user validation email
        public ActionResult EmailValidation(string email, string InitialEmail)
        {
            if(email == InitialEmail)
                return Json(true, JsonRequestBehavior.AllowGet);

            using (hercules_dbEntities db = new hercules_dbEntities())
            {
                try
                {
                    var tag = db.users.Single(m => m.Email == email);
                    return Json(false, JsonRequestBehavior.AllowGet);
                }
                catch (Exception)
                {
                    return Json(true, JsonRequestBehavior.AllowGet);
                }
            }
        }
예제 #11
0
        public ActionResult Create(users us)
        {
            if (ModelState.IsValid)
            {
                using (var northwind = new hercules_dbEntities())
                {
                      //Get max ID table loggers
                    var crum = northwind.users.Max(sd => sd.Id);

                    int current_id = Convert.ToInt32(crum.ToString());

                    var entity = new users
                    {

                        Id = current_id+1,
                        FirstName = us.FirstName,
                        LastName = us.LastName,
                        Username = us.Username,
                        Password = us.Password,
                        Email = us.Email,
                        Mobile = us.Mobile,
                        DateCreated = DateTime.Now,
                        Role = us.Role,
                        RecieveNotifications = us.RecieveNotifications,
                        Status = true,
                        CompanyID = Convert.ToInt16(Session["CompanyID"].ToString())

                    };
                    // Add the entity
                    northwind.users.Add(entity);
                    // Insert the entity in the database
                    northwind.SaveChanges();
                    return RedirectToAction("List");
                }
            }
             else{

                return View(us);
            }
        }
예제 #12
0
        public ActionResult Edit([DataSourceRequest] DataSourceRequest request, zone product)
        {
            //  DataClasses1DataContext dt = new DataClasses1DataContext();
            if (product != null)
              //  && ModelState.IsValid
            {

                using (var db = new hercules_dbEntities())
                {
                    var result = from u in db.zones2 where (u.ID == product.ID) select u;
                    if (result.Count() != 0)
                    {
                        var dbuser = result.First();
                        dbuser.ZoneName = product.ZoneName;
                        dbuser.Status = product.Status.Value;

                        db.SaveChanges();
                    }
                }

            }

            return Json(new[] { product }.ToDataSourceResult(request, ModelState));
        }
예제 #13
0
        public ActionResult Create(sites d)
        {
            if (ModelState.IsValid)
            {
                using (var db = new hercules_dbEntities())
                {
                    //Get max ID table loggers
                    var crum = db.loggers.Max(sd => sd.ID);

                    int current_id = Convert.ToInt32(crum.ToString());

                    //list logger
                    string[] temporale;
                    ArrayList id_logger = new ArrayList();
                    ArrayList type_logger = new ArrayList();

                    int limit_pcp = 0 ;
                    int limit_erp =0;
                    IEnumerable source = d.SelectedLogger;
                    if (source != null)
                    {
                        foreach (var element in source)
                        {
                            temporale = element.ToString().Split(' ');
                            type_logger.Add(temporale[0].ToString());
                            id_logger.Add(temporale[1].ToString());
                            if (temporale[0].ToString() == "PCP")
                                limit_pcp = limit_pcp + 1;
                            if (temporale[0].ToString() == "ERP")
                                limit_erp = limit_erp + 1;
                        }

                        if (limit_erp > 1){
                            ViewBag.DataExists = true;
                            //ViewBag.Javascript = "<script language='javascript' type='text/javascript'>alert('Max 1 ERP by Site');</script>";
                            return RedirectToAction("Create");
                        }
                        else if (limit_pcp > 3)
                        {
                            ViewBag.DataExists = true;
                            //ViewBag.Javascript = "<script language='javascript' type='text/javascript'>alert('Max 3 PCP by Site');</script>";
                            return RedirectToAction("Create");
                        }
                        else
                        {
                            for (int i = 0; i < id_logger.Count; i++)
                            {
                                int id =Convert.ToInt16(id_logger[i]);
                                var result = from u in db.loggers where (u.ID == id ) select u;
                                if (result.Count() != 0)
                                {
                                    var dblogger = result.First();
                                    dblogger.SiteID = current_id;
                                    db.SaveChanges();
                                }
                            }
                        }

                    }

                    var entity = new sites
                    {
                        ID = current_id + 1,
                        Address = d.Address,
                        ZoneID = d.ZoneID,
                        Notes = d.Notes,
                        CompanyID = Convert.ToInt16(Session["CompanyID"].ToString()),
                        CreateDate = DateTime.Now,
                        OwnerAccount = Convert.ToInt16(Session["LogedUserID"].ToString()),

                    };
                    // Add the entity
                    db.sites.Add(entity);
                    // Insert the entity in the database
                    db.SaveChanges();

                }
                RedirectToAction("List");
                return View();
            }
            else

                return View();
        }
예제 #14
0
        private IEnumerable<dynamic> GetData()
        {
            var db = new hercules_dbEntities();

            var result = from a in db.sites
                         join b in db.zones2
                             on new { emp = a.ZoneID } equals new { emp = b.ID }
                         select new
                         {
                              a.ID,
                              Adress = a.Address,
                              CreationDate = a.CreateDate,
                              ZoneID = b.ID,
                              ZoneName = b.ZoneName
                         };
            //result = result.Where(u => u. == true);
            result = result.OrderBy(u => u.CreationDate);
            return result;
        }
예제 #15
0
        private IEnumerable<dynamic> GetData()
        {
            var ZoneLogger = new hercules_dbEntities();

            var result = from a in ZoneLogger.zones2
                         select new
                         {
                             ID = a.ID,
                             ZoneName = a.ZoneName,
                             Status = a.Status,
                             CreationDate = a.CreationDate
                         };

            return result;
        }
예제 #16
0
        public ActionResult Edit(int Id)
        {
            hercules_dbEntities db = new hercules_dbEntities();

            return View("Edit", db.users.Find(Id));
        }
예제 #17
0
        private IEnumerable<dynamic> GetData()
        {
            var db = new hercules_dbEntities();

            var result = from a in db.users
                         join b in db.roles
                            on a.Role equals b.RoleId

                         select new
                         {
                             a.Id,
                             Name = a.FirstName,
                             a.Username,
                             a.Email,
                             a.Mobile,
                             UserLevel = b.Description,
                             UserLevelID = b.RoleId,
                             a.LastLogin,
                             CreationDate = a.DateCreated,
                             a.Status

                         };
            result = result.OrderBy(u => u.CreationDate);
            return result;
        }
예제 #18
0
        private IEnumerable<dynamic> GetData()
        {
            var db = new hercules_dbEntities();
            var zone = new ZoneLogger();
            var result = from a in db.loggers
                        //join b in db.sites
                        //    on a.ID equals b.LoggerID into abc from ab in abc.DefaultIfEmpty()
                        join c in db.users
                            on a.OwnerAccount equals c.Id
                        select new
                        {
                            ID = a.ID,
                            LoggerSMSNumber = a.LoggerSMSNumber,
                            BatteryLevel = a.BatteryLevel,
                            LastCallIn = a.LastCallIn,
                            LoggerSerialNumber = a.LoggerSerialNumber,
                            LoggerType = a.LoggerType,
                            SignalLevel = a.SignalLevel,
                            Owner = c.FirstName +" "+ c.LastName,
                            OwnerID = c.Id,
                            a.LoggerStatus,
                            a.CreationDate,
                            a.Adress

                        };
            result = result.Where(u => u.LoggerStatus == true);
            result = result.OrderBy(u => u.CreationDate);
            return result ;
        }
예제 #19
0
        public ActionResult Edit([DataSourceRequest] DataSourceRequest request, loggers us)
        {
            if (ModelState.IsValid)
            {
                using (var db = new hercules_dbEntities())
                {
                    var result = from u in db.loggers where (u.ID == us.ID) select u;
                    if (result.Count() != 0)
                    {
                        var dblogger = result.First();

                        dblogger.LoggerSMSNumber = us.LoggerSMSNumber;
                        dblogger.LoggerSerialNumber = us.LoggerSerialNumber;
                        dblogger.Notes = us.Notes;
                        dblogger.Adress = us.Adress;
                        dblogger.LatEast = us.LatEast;
                        dblogger.LongNorth = us.LongNorth;
                        dblogger.HeightAOD = us.HeightAOD;
                        dblogger.LoggerTypeClass = us.LoggerTypeClass;
                        if(us.SiteID != null)
                        dblogger.SiteID = us.SiteID;

                        db.SaveChanges();
                    }
                }
            }

            return RedirectToAction("ListLogger");
        }
예제 #20
0
        //Adress Site
        public ActionResult ZoneValidation(string ZoneName, string InitialAddess)
        {
            if (ZoneName == InitialAddess)
                return Json(true, JsonRequestBehavior.AllowGet);

            using (hercules_dbEntities db = new hercules_dbEntities())
            {
                try
                {
                    var tag = db.zones2.Single(m => m.ZoneName == ZoneName);
                    return Json(false, JsonRequestBehavior.AllowGet);
                }
                catch (Exception)
                {
                    return Json(true, JsonRequestBehavior.AllowGet);
                }
            }
        }