public ActionResult Settings(AppSetting model)
        {
            if (model.TemperatureLower >= model.TemperatureUpper)
            {
                ModelState.AddModelError("", Resources.Resources.TemperatureThresholdConfigError);
            }

            if (model.HumidityLower >= model.HumidityUpper)
            {
                ModelState.AddModelError("", Resources.Resources.HumidityThresholdConfigError);
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            appSettingRepository.Update(model);
            auditLogRepository.Add(AuditLogBuilder.Builder()
                                   .User(Identity.Name)
                                   .Updated(typeof(AppSetting), model.Id.ToString())
                                   .With(new ChangeInfo()
                                         .AddChange(() => model.TemperatureUpper)
                                         .AddChange(() => model.TemperatureLower)
                                         .AddChange(() => model.Battery)
                                         .AddChange(() => model.HumidityUpper)
                                         .AddChange(() => model.HumidityLower)
                                         .ToJson()).Build());
            logger.Info("User '{0}' updated system setting.", Identity.Name);

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult Delete(int id)
        {
            if (userRepository.FindAll(user => user.AreaId == id, null).Any())
            {
                TempData[MESSAGE_KEY] = Resources.Resources.MsgCanNotDeleteAreaWithUser;
                return(RedirectToAction("Index"));
            }

            if (deviceRepository.FindAll(device => device.AreaId == id, null).Any())
            {
                TempData[MESSAGE_KEY] = Resources.Resources.MsgCanNotDeleteAreaWithDevice;
                return(RedirectToAction("Index"));
            }

            if (areaRepository.Count() == 1)
            {
                TempData[MESSAGE_KEY] = Resources.Resources.MsgAtLeastOneAreaInSystem;
                return(RedirectToAction("Index"));
            }

            Area existing = areaRepository.Get(id);

            areaRepository.Delete(existing);

            auditLogRepository.Add(
                AuditLogBuilder.Builder()
                .User(HttpContext.User.Identity.Name)
                .Deleted(typeof(Area), existing.Name)
                .With(new ChangeInfo().AddChange(() => existing.Name).ToJson())
                .Build());

            logger.Info("User '{0}' deleted area '{1}'.", Identity.Name, existing.Name);
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(User model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Areas = GetAreaSelectItems();
                return(View(model));
            }
            if (userRepository.GetByUserName(model.UserName) != null)
            {
                ModelState.AddModelError("UserName", Resources.Resources.MsgUserNameAlreadyExists);
                ViewBag.Areas = GetAreaSelectItems();
                return(View(model));
            }


            HashUserPassword(model, model.Password);
            userRepository.Add(model);

            auditLogRepository.Add(AuditLogBuilder.Builder()
                                   .User(Identity.Name)
                                   .Added(typeof(User), model.UserName)
                                   .With(new ChangeInfo().AddChange(() => model.UserName).ToJson())
                                   .Build());

            logger.Info("User '{0}' created new user '{1}'", Identity.Name, model.UserName);
            return(RedirectToAction("Index"));
        }
        private void AuditUserUpdate(User updated)
        {
            string changeInfo = new ChangeInfo()
                                .AddChange(() => updated.Phone)
                                .AddChange(() => updated.Email)
                                .AddChange(() => updated.AreaId)
                                .ToJson();

            auditLogRepository.Add(
                AuditLogBuilder.Builder()
                .User(HttpContext.User.Identity.Name)
                .Updated(typeof(User), updated.UserName)
                .With(changeInfo).Build());
        }
Exemple #5
0
        private void AuditAreaChange(Area existing)
        {
            string changeInfo = new ChangeInfo()
                                .AddChange(() => existing.Name)
                                .AddChange(() => existing.Description)
                                .AddChange(() => existing.ParentId)
                                .ToJson();

            auditLogRepository.Add(
                AuditLogBuilder.Builder()
                .User(HttpContext.User.Identity.Name)
                .Updated(typeof(Area), existing.Name)
                .With(changeInfo)
                .Build());
        }
Exemple #6
0
        public ActionResult Delete(int id)
        {
            Device exising = deviceRepository.Get(id);

            deviceRepository.Delete(exising);

            auditLogRepository.Add(AuditLogBuilder.Builder()
                                   .User(HttpContext.User.Identity.Name)
                                   .Deleted(typeof(Device), exising.Name)
                                   .With(new ChangeInfo().AddChange(() => exising.Name).ToJson())
                                   .Build());

            logger.Info("User '{0}' deleted device '{1}'.", Identity.Name, exising.Name);

            return(RedirectToAction("TableMode"));
        }
Exemple #7
0
        private void AuditDeviceChange(Device existing)
        {
            string changes = new ChangeInfo()
                             .AddChange(() => existing.Name)
                             .AddChange(() => existing.Description)
                             .AddChange(() => existing.SimNumber)
                             .AddChange(() => existing.IMEI)
                             .AddChange(() => existing.AreaId)
                             .AddChange(() => existing.DeviceMetaId)
                             .ToJson();

            auditLogRepository.Add(AuditLogBuilder.Builder()
                                   .User(HttpContext.User.Identity.Name)
                                   .Updated(typeof(Device), existing.Name)
                                   .With(changes)
                                   .Build());
        }
Exemple #8
0
        public ActionResult Delete(int id)
        {
            var exising = transportPlanRepository.Get(id);

            if (exising == null)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }
            transportPlanRepository.Delete(exising);

            auditLogRepository.Add(AuditLogBuilder.Builder()
                                   .User(HttpContext.User.Identity.Name)
                                   .Deleted(typeof(TransportPlan), exising.Name)
                                   .With(new ChangeInfo().AddChange(() => exising.Name).ToJson())
                                   .Build());

            logger.Info("User '{0}' deleted TransportPlan '{1}'.", Identity.Name, exising.Name);

            return(RedirectToAction("Index"));
        }
Exemple #9
0
        public ActionResult Create(TransportPlan model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            transportPlanRepository.Add(model);


            auditLogRepository.Add(AuditLogBuilder.Builder()
                                   .User(HttpContext.User.Identity.Name)
                                   .Added(typeof(TransportPlan), model.Name)
                                   .With(new ChangeInfo().AddChange(() => model.Name).ToJson())
                                   .Build());

            logger.Info("User '{0}' created TransportPlan '{1}'.", Identity.Name, model.Name);

            return(RedirectToAction("Index"));
        }
Exemple #10
0
        public ActionResult Create(AreaModel areaModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Areas = GetCurrentSelectableAreaItems();
                return(View(areaModel));
            }

            areaRepository.Add(viewModelToArea(areaModel));

            auditLogRepository.Add(
                AuditLogBuilder.Builder()
                .User(HttpContext.User.Identity.Name)
                .Added(typeof(Area), areaModel.Name)
                .With(new ChangeInfo().AddChange(() => areaModel.Name).ToJson())
                .Build());

            logger.Info("User '{0}' created area '{1}'.", Identity.Name, areaModel.Name);

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int id)
        {
            User existing = userRepository.Get(id);

            if (existing.UserName.Equals("admin"))
            {
                TempData[MESSAGE_KEY] = Resources.Resources.MsgCanNotDeleteAdmin;
                return(RedirectToAction("Index"));
            }

            userRepository.Delete(existing);

            auditLogRepository.Add(AuditLogBuilder.Builder()
                                   .User(HttpContext.User.Identity.Name)
                                   .Deleted(typeof(User), existing.UserName)
                                   .With(new ChangeInfo().AddChange(() => existing.UserName).ToJson())
                                   .Build());

            logger.Info("User '{0}' deleted user '{1}'.", Identity.Name, existing.UserName);
            return(RedirectToAction("Index"));
        }
Exemple #12
0
        public ActionResult Create(DeviceModel deviceModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Areas       = GetAreaSelectItems();
                ViewBag.Plans       = GetPlanSelectItems();
                ViewBag.DeviceTypes = GetDeviceTypeItems();
                return(View(deviceModel));
            }

            var device = new Device();

            UpdateDeviceFromModel(device, deviceModel);
            deviceRepository.Add(device);

            if (device.TransportPlanId != null)
            {
                devicePlanRepository.Add(new DevicePlanRecord {
                    DeviceId = device.Id, PlanId = device.TransportPlanId, startTime = DateTime.Now
                });
            }

            dtuGpsRepository.Add(new DtuGPS
            {
                IMEI      = deviceModel.IMEI,
                RecvTime  = DateTime.Now,
                Longitude = deviceModel.longitude,
                Latitude  = deviceModel.latitude
            });

            auditLogRepository.Add(AuditLogBuilder.Builder()
                                   .User(HttpContext.User.Identity.Name)
                                   .Added(typeof(Device), device.Name)
                                   .With(new ChangeInfo().AddChange(() => device.Name).ToJson())
                                   .Build());

            logger.Info("User '{0}' created device '{1}'.", Identity.Name, device.Name);

            return(RedirectToAction("TableMode"));
        }