public int Add(AlarmAddModel mAlarm) { var location = _context.Locations.FirstOrDefault(a => a.LocationId == mAlarm.LocationId); if (location == null) { throw new ExpectException("Could not find Location data which LocationId equal to " + mAlarm.LocationId); } var alarmMessage = _context.AlarmMessages.FirstOrDefault(a => a.AlarmMessageId == mAlarm.AlarmMessageId); if (alarmMessage == null) { throw new ExpectException("Could not find AlarmMessage data which AlarmMessageId equal to " + mAlarm.AlarmMessageId); } var model = new Alarm { AlarmMessageId = mAlarm.AlarmMessageId, LocationId = mAlarm.LocationId, CreateDate = DateTime.Now }; _context.Alarms.Add(model); _context.SaveChanges(); return(model.AlarmId); }
public int Add(ProjectAddModel project) { var customer = _context.Customers.FirstOrDefault(c => c.CustomerId == project.CustomerId); if (customer == null) { throw new ExpectException("Could not find Customer data which CustomerId equal to " + project.CustomerId); } //ProjectNo must be unique var checkData = _context.Projects.Where(p => p.ProjectNo == project.ProjectNo).ToList(); if (checkData.Count > 0) { throw new ExpectException("The data which ProjectNo equal to '" + project.ProjectNo + "' already exist in system"); } //Get UserInfo var user = _loginUser.GetLoginUserInfo(); var model = new Project { CustomerId = project.CustomerId, ProjectName = project.ProjectName, ProjectNo = project.ProjectNo, Creator = user.UserName, CreateDate = DateTime.Now }; _context.Projects.Add(model); _context.SaveChanges(); return(model.ProjectId); }
public int Add(CustomerAddModel customer) { //CustomerNo must be unique var checkData = _context.Customers.Where(c => c.CustomerNo == customer.CustomerNo).ToList().Count; if (checkData > 0) { throw new ExpectException("The data which CustomerNo equal to '" + customer.CustomerNo + "' already exist in system"); } //Get UserInfo var user = _loginUser.GetLoginUserInfo(); var model = new Customer { CustomerName = customer.CustomerName, CustomerNo = customer.CustomerNo, Creator = user.UserName, CreateDate = DateTime.Now }; _context.Customers.Add(model); _context.SaveChanges(); return(model.CustomerId); }
public int Add(LogAddModel mLog) { var location = _context.Locations.FirstOrDefault(a => a.LocationId == mLog.LocationId); if (location == null) { throw new ExpectException("Could not find Location data which LocationId equal to " + mLog.LocationId); } var logDescription = _context.LogDescriptions.FirstOrDefault(a => a.LogDescriptionId == mLog.LogDescriptionId); if (logDescription == null) { throw new ExpectException("Could not find LogDescription data which LogDescriptionId equal to " + mLog.LogDescriptionId); } var user = _loginUser.GetLoginUserInfo(); var model = new Log { Comment = mLog.Comment, LocationId = mLog.LocationId, LogDescriptionId = mLog.LogDescriptionId, Creator = user.UserName, CreateDate = DateTime.Now }; _context.Logs.Add(model); _context.SaveChanges(); return(model.LogId); }
public int Add(SceneSegmentAddModel mSceneSegment) { var scene = _context.Scenes.FirstOrDefault(c => c.SceneId == mSceneSegment.SceneId); if (scene == null) { throw new ExpectException("Could not find Scene data which SceneId equal to " + mSceneSegment.SceneId); } //SequenceNo must be unique var checkData = _context.SceneSegments.Where(s => s.SequenceNo == mSceneSegment.SequenceNo).ToList(); if (checkData.Count > 0) { throw new ExpectException("The data which SequenceNo equal to '" + mSceneSegment.SequenceNo + "' already exist in system"); } //Get UserInfo var user = _loginUser.GetLoginUserInfo(); var model = new SceneSegment { SceneId = mSceneSegment.SceneId, SequenceNo = mSceneSegment.SequenceNo, StartTime = mSceneSegment.StartTime, Volumn = mSceneSegment.Volumn, Creator = user.UserName, CreateDate = DateTime.Now }; _context.SceneSegments.Add(model); _context.SaveChanges(); return(model.SceneSegmentId); }
public int Add(SceneAddModel scene) { var project = _context.Projects.FirstOrDefault(c => c.ProjectId == scene.ProjectId); if (project == null) { throw new ExpectException("Could not find Project data which ProjectId equal to " + scene.ProjectId); } //SceneName must be unique var checkData = _context.Scenes.Where(s => s.SceneName == scene.SceneName).ToList(); if (checkData.Count > 0) { throw new ExpectException("The data which SceneName equal to '" + scene.SceneName + "' already exist in system"); } //Get UserInfo var user = _loginUser.GetLoginUserInfo(); var model = new Scene { ProjectId = scene.ProjectId, SceneName = scene.SceneName, Enable = scene.Enable, Creator = user.UserName, CreateDate = DateTime.Now }; _context.Scenes.Add(model); _context.SaveChanges(); return(model.SceneId); }
public void RemoveById(int locationId) { var location = _context.Locations.FirstOrDefault(l => l.LocationId == locationId); if (location == null) { throw new ExpectException("Could not find data which DeviceLocation equal to " + locationId); } _context.Remove(location); _context.SaveChanges(); }
public int Add(DeviceAddModel mDevice) { var model = new Device { Voltage = mDevice.Voltage, Diameter = mDevice.Diameter, Torque = mDevice.Torque, }; _context.Devices.Add(model); _context.SaveChanges(); return(model.DeviceId); }
public void Remove(Guid locationId, int motorLocationNumber) { var _installedMotor = this._context.InstalledMotors .Where(m => m.LocationId == locationId && m.MotorLocationNumber == motorLocationNumber) .First <InstalledMotor>(); this._context.Remove(_installedMotor); // remove date form the related table var _location = _context.Locations.Where(l => l.LocaitonId == locationId).Single <Location>(); _context.Locations.Remove(_location); _context.SaveChanges(); }
public void Remove(Guid projectId) { var _project = this._context.Projects .Where(p => p.ProjectId == projectId) .First <Project>(); this._context.Remove(_project); //// remove date form the related table //var _groupMotor = _context.GroupInstalledMotors.Where(gl => gl.GroupId == _group.GroupId); //foreach (var gl in _groupMotor) //{ // _context.GroupInstalledMotors.Remove(gl); //} _context.SaveChanges(); }
public void Remove(MGroup mGroup) { var _group = this._context.Groups .Where(g => g.ProjectId == mGroup.ProjectId && g.GroupName == mGroup.GroupName) .First <Group>(); this._context.Remove(_group); // remove date form the related table var _groupMotor = _context.GroupInstalledMotors.Where(gl => gl.GroupId == _group.GroupId); foreach (var gl in _groupMotor) { _context.GroupInstalledMotors.Remove(gl); } _context.SaveChanges(); }
public void Remove(Guid projectId, Guid locationId) { var _location = this._context.Locations .Where(l => l.ProjectId == projectId && l.LocaitonId == locationId) .First <Location>(); this._context.Remove(_location); // remove date form the event table manually var _event = _context.Events.Where(e => e.ProjectId == projectId); foreach (var e in _event) { _context.Events.Remove(e); } _context.SaveChanges(); }
public int Add(GroupAddModel group) { var project = _context.Projects.FirstOrDefault(p => p.ProjectId == group.ProjectId); if (project == null) { throw new ExpectException("Could not find Project data which ProjectId equal to " + group.ProjectId); } //If SceneId not null,check whether corresponding Scenes data existed if (group.SceneId != null) { var scene = _context.Scenes.FirstOrDefault(p => p.SceneId == group.SceneId); if (scene == null) { throw new ExpectException("Could not find Scenes data which SceneId equal to " + group.SceneId); } } //GroupName must be unique var checkData = _context.Groups.Where(g => g.GroupName == group.GroupName).ToList(); if (checkData.Count > 0) { throw new ExpectException("The data which GroupName equal to '" + group.GroupName + "' already exist in system."); } //Get UserInfo var user = _loginUser.GetLoginUserInfo(); var model = new Group { GroupName = group.GroupName, ProjectId = group.ProjectId, SceneId = group.SceneId, Creator = user.UserName, CreateDate = DateTime.Now }; _context.Groups.Add(model); _context.SaveChanges(); return(model.GroupId); }
public int Add(LogDescriptionAddModel mLogDescription) { //DescriptionCode must be unique var checkData = _context.LogDescriptions .Where(c => c.DescriptionCode == mLogDescription.DescriptionCode).ToList(); if (checkData.Count > 0) { throw new ExpectException("The data which DescriptioncODE equal to " + mLogDescription.DescriptionCode + " already exist in system"); } var model = new LogDescription { DescriptionCode = mLogDescription.DescriptionCode, Description = mLogDescription.Description }; _context.LogDescriptions.Add(model); _context.SaveChanges(); return(model.LogDescriptionId); }
public int Add(AlarmMessageAddModel mAlarmMessage) { //ErrorCode must be unique var checkData = _context.AlarmMessages .Where(c => c.ErrorCode == mAlarmMessage.ErrorCode).ToList(); if (checkData.Count > 0) { throw new ExpectException("The data which ErrorCode equal to " + mAlarmMessage.ErrorCode + " already exist in system"); } var model = new AlarmMessage { ErrorCode = mAlarmMessage.ErrorCode, Message = mAlarmMessage.Message }; _context.AlarmMessages.Add(model); _context.SaveChanges(); return(model.AlarmMessageId); }
public int Add(GroupLocationAddModel mGroupLocation) { var group = _context.Groups.FirstOrDefault(c => c.GroupId == mGroupLocation.GroupId); if (group == null) { throw new ExpectException("Could not find Group data which GroupId equal to " + mGroupLocation.GroupId); } var location = _context.Locations.FirstOrDefault(c => c.LocationId == mGroupLocation.LocationId); if (location == null) { throw new ExpectException("Could not find Location data which LocationId equal to " + mGroupLocation.LocationId); } //GroupId and LocationId must be unique var checkData = _context.GroupLocations .Where(c => c.GroupId == mGroupLocation.GroupId && c.LocationId == mGroupLocation.LocationId).ToList(); if (checkData.Count > 0) { throw new ExpectException("There is already exist data which GroupId equal to " + mGroupLocation.GroupId + " and LocationId equal to " + mGroupLocation.LocationId); } var model = new GroupLocation { GroupId = mGroupLocation.GroupId, LocationId = mGroupLocation.LocationId }; _context.GroupLocations.Add(model); _context.SaveChanges(); return(model.GroupLocationId); }
public int Add(UserGroupAddModel mUserGroup) { var group = _context.Groups.FirstOrDefault(c => c.GroupId == mUserGroup.GroupId); if (group == null) { throw new ExpectException("Could not find Group data which GroupId equal to " + mUserGroup.GroupId); } var user = _context.Users.FirstOrDefault(c => c.Id == mUserGroup.UserId); if (user == null) { throw new ExpectException("Could not find User data which UserId equal to '" + mUserGroup.UserId + "'"); } //GroupId and UserId must be unique var checkData = _context.UserGroups .Where(c => c.GroupId == mUserGroup.GroupId && c.UserId == mUserGroup.UserId).ToList(); if (checkData.Count > 0) { throw new ExpectException("There is already exist data which GroupId equal to " + mUserGroup.GroupId + " and UserId equal to '" + mUserGroup.UserId + "'"); } var model = new UserGroup { GroupId = mUserGroup.GroupId, UserId = mUserGroup.UserId }; _context.UserGroups.Add(model); _context.SaveChanges(); return(model.UserGroupId); }
public int Add(UserLocationAddModel mUserLocation) { var location = _context.Locations.FirstOrDefault(c => c.LocationId == mUserLocation.LocationId); if (location == null) { throw new ExpectException("Could not find Location data which LocationId equal to " + mUserLocation.LocationId); } var user = _context.Users.FirstOrDefault(c => c.Id == mUserLocation.UserId); if (user == null) { throw new ExpectException("Could not find User data which UserId equal to '" + mUserLocation.UserId + "'"); } //LocationId and UserId must be unique var checkData = _context.UserLocations .Where(c => c.LocationId == mUserLocation.LocationId && c.UserId == mUserLocation.UserId).ToList(); if (checkData.Count > 0) { throw new ExpectException("There is already exist data which LocationId equal to " + mUserLocation.LocationId + " and UserId equal to '" + mUserLocation.UserId + "'"); } var model = new UserLocation { LocationId = mUserLocation.LocationId, UserId = mUserLocation.UserId }; _context.UserLocations.Add(model); _context.SaveChanges(); return(model.UserLocationId); }
public int Add(HolidayAddModel mHoliday) { var project = _context.Projects.FirstOrDefault(c => c.ProjectId == mHoliday.ProjectId); if (project == null) { throw new ExpectException("Could not find Project data which ProjectId equal to " + mHoliday.ProjectId); } //Get UserInfo var user = _loginUser.GetLoginUserInfo(); var model = new Holiday { ProjectId = mHoliday.ProjectId, Day = mHoliday.Day, Creator = user.UserName, CreateDate = DateTime.Now }; _context.Holidays.Add(model); _context.SaveChanges(); return(model.HolidayId); }
public void Add(MEvent mEvent) { _context.Events.Add(new Event { EventId = new Guid(), ProjectId = mEvent.ProjectId, LocationId = mEvent.LocationId, EventMessageId = this._context.EventMessages .Where(em => em.MessageCode == mEvent.MessageCode) .FirstOrDefault().EventMessageId, ModifiedDate = DateTime.Now }); _context.SaveChanges(); }