public void CreateTAReport(int userId, int?departmentId, string name, DateTime ReportDate, Int16 day, float hours, int shift, byte status, Boolean completed, Boolean isDeleted) { using (IUnitOfWork work = UnitOfWork.Begin()) { TAReport taReport = new TAReport(); taReport = DomainObjectFactory.CreateTAReport(); taReport.UserId = userId; taReport.DepartmentId = departmentId; taReport.Name = name; //taReport.YearMonth = yearMonth; taReport.Day = day; taReport.Hours = hours; taReport.ReportDate = ReportDate; TimeSpan t = TimeSpan.FromSeconds(hours); taReport.Hours_Min = string.Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds); taReport.Shift = shift; taReport.Status = status; taReport.Completed = completed; taReport.IsDeleted = isDeleted; taReport.Timestamp = BitConverter.GetBytes(DateTime.Now.Ticks); taReport.ModifiedLast = DateTime.Now; taReport.ModifiedId = CurrentUser.Get().Id; _taReportRepository.Add(taReport); work.Commit(); var taReportLogEntity = new TAReportEventEntity(taReport); _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, taReportLogEntity.GetCreateMessage()); string taReport_value = string.Format("{0} {1} {2}", name, hours, taReport.ModifiedLast.ToString("dd.MM.yyyy")); _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, taReport.Id, UpdateParameter.TAReportChange, ControllerStatus.Created, taReport_value); } }
public void CreateHoliday(string name, string createdBy, DateTime eventStart, DateTime eventEnd, bool holidayMoving) { using (IUnitOfWork work = UnitOfWork.Begin()) { Holiday holiday = DomainObjectFactory.CreateHoliday(); holiday.Name = name; holiday.EventStart = eventStart; holiday.EventEnd = eventStart; //eventEnd; holiday.ModifiedLast = DateTime.Now; holiday.ModifiedBy = createdBy; holiday.MovingHoliday = holidayMoving; holiday.IsDeleted = false; _holidayRepository.Add(holiday); work.Commit(); var holidayLogEntity = new HolidayEventEntity(holiday); _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, holidayLogEntity.GetCreateMessage()); string holiday_value = string.Format("{0} {1} {1}", name, eventStart.ToString("dd.MM.yyyy")); _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, holiday.Id, UpdateParameter.HolidayChange, ControllerStatus.Created, holiday_value); } }
public bool CardIsBack(int id) { using (IUnitOfWork work = UnitOfWork.Begin()) { try { UsersAccessUnit usersAccessUnit = _usersAccessUnitRepository.FindById(id); usersAccessUnit.Closed = DateTime.Now; usersAccessUnit.ValidTo = DateTime.Now.AddDays(-1); usersAccessUnit.Comment = ""; work.Commit(); var msg = string.Format("Card is Back ! User:{0}. Card:{1}", usersAccessUnit.User.LoginName.ToString(), usersAccessUnit.CardFullCode); _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, msg); _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, id, UpdateParameter.UserCardChange, ControllerStatus.Edited, msg); } catch (Exception) { return(false); } return(true); } }
public void CreateTAMove(int userId, int departmentId, string name, DateTime ReportDate, Int16 day, float hours, int shift, byte status, Boolean completed, Boolean isDeleted) { int _hours, _minutes; using (IUnitOfWork work = UnitOfWork.Begin()) { TAReport taReport = DomainObjectFactory.CreateTAReport(); taReport.UserId = userId; taReport.DepartmentId = departmentId; taReport.Name = name; //taReport.YearMonth = yearMonth; taReport.Day = day; taReport.Hours = hours; _hours = (int)Math.Floor(hours); // täisarvulised tunnid _minutes = (int)((hours - _hours) * 60) % 60; // murdosa minutiteks taReport.Hours_Min = Convert.ToString(_hours) + ':'; if (_minutes < 10) { taReport.Hours_Min = taReport.Hours_Min + Convert.ToString(_minutes); } else { taReport.Hours_Min = taReport.Hours_Min + '0' + Convert.ToString(_minutes); } taReport.Shift = shift; taReport.Status = status; taReport.Completed = completed; taReport.IsDeleted = isDeleted; taReport.Timestamp = BitConverter.GetBytes(DateTime.Now.Ticks); // taReport.ScheduleNo = 1; taReport.ModifiedLast = DateTime.Now; taReport.ModifiedId = CurrentUser.Get().Id; _taReportRepository.Add(taReport); work.Commit(); var taReportLogEntity = new TAReportEventEntity(taReport); _logService.CreateLog(CurrentUser.Get().Id, "web", falg, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, taReportLogEntity.GetCreateMessage()); string taReport_value = string.Format("{0} {1} {2}", name, hours, taReport.ModifiedLast.ToString("dd.MM.yyyy")); _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, taReport.Id, UpdateParameter.TAReportChange, ControllerStatus.Created, taReport_value); } }
public void CreateHolidayBuilding(int holidayId, int BuildingId) { using (IUnitOfWork work = UnitOfWork.Begin()) { if (_HolidayBuildingRepository.FindAll().Where(x => x.HoliDayId == holidayId && x.BuildingId == BuildingId).Any()) { _HolidayBuildingRepository.FindAll().Where(x => x.HoliDayId == holidayId && x.BuildingId == BuildingId).First().IsDeleted = false; } else { HolidayBuilding hb = DomainObjectFactory.CreateHolidayBuilding(); hb.HoliDayId = holidayId; hb.BuildingId = BuildingId; hb.IsDeleted = false; _HolidayBuildingRepository.Add(hb); } work.Commit(); _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, "Holiday buildings changed"); _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, holidayId, UpdateParameter.HolidayChange, ControllerStatus.Edited, string.Empty); } }
public RoleCreateResult CreateRole(string name, string description, string createdBy, bool active, int roleTypeId, IEnumerable <RoleBuildingDto> buildings, IEnumerable <int> permissionIds = null, IEnumerable <int> menuIds = null) { var result = new RoleCreateResult { ErrorCode = RoleServiceErrorCode.Ok }; if (_roleRepository.FindByName(name).Count() != 0) { result.ErrorCode = RoleServiceErrorCode.RoleAlreadyExists; return(result); } using (IUnitOfWork work = UnitOfWork.Begin()) { Role role = DomainObjectFactory.CreateRole(); role.Name = name; role.Description = description; role.RoleTypeId = roleTypeId; role.AssignPermissions(permissionIds.NullSafe()); role.AssignMenues(menuIds.NullSafe()); role.ModifiedLast = DateTime.Now; role.ModifiedBy = createdBy; role.Active = active; role.IsDeleted = false; role.StaticId = -1; role.UserId = CurrentUser.Get().Id; foreach (var building in buildings) { if (building.IsChecked) { var roleBuilding = DomainObjectFactory.CreateRoleBuilding(); roleBuilding.RoleId = role.Id; roleBuilding.BuildingId = building.BuildingId.Value; roleBuilding.IsDeleted = false; role.RoleBuildings.Add(roleBuilding); } } _roleRepository.Add(role); work.Commit(); IFoxSecIdentity identity = CurrentUser.Get(); var e = new RoleCreatedEventArgs(role, identity.LoginName, identity.FirstName, identity.LastName, DateTime.Now); var logRoleEntity = new RoleEventEntity(_roleRepository.FindById(role.Id)); _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, logRoleEntity.GetCreateMessage()); // _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, CurrentUser.Get().Id, UpdateParameter.UserStatusChanged, ControllerStatus.Created, "Active"); EventAggregator.GetEvent <RoleCreatedEvent>().Publish(e); _conrtollerCreateService.CreateControllerUpdate(CurrentUser.Get().Id, CurrentUser.Get().Id, UpdateParameter.UserRoleManagement, ControllerStatus.Created, "Active"); } return(result); }
/* public VisitorCreateResult CreateVisitor(string carNr, int? userId, string firstName, string carType, System.DateTime startDateTime, System.DateTime stopDateTime, int? companyId, string lastName, string company, int? parentVisitorsId, DateTime? returnDate, string email, string host, string phoneNumber) * { * * var result = new VisitorCreateResult { ErrorCode = UserServiceErrorCode.Ok, Id = 0 }; * * * using(IUnitOfWork work = UnitOfWork.Begin()){ * * Visitor visitor = DomainObjectFactory.CreateVisitor(); * IFoxSecIdentity identity = CurrentUser.Get(); * * visitor.CarNr = carNr; * visitor.UserId = userId; * visitor.FirstName = firstName; * visitor.CarType = carType; * visitor.StartDateTime = startDateTime; * visitor.StopDateTime = stopDateTime; * visitor.CompanyId = companyId; * visitor.LastName = lastName; * visitor.Company = company; * visitor.ParentVisitorsId = parentVisitorsId; * visitor.ReturnDate = returnDate; * // visitor.Email = string.IsNullOrEmpty(email) ? "" : email; //error * visitor.Email = email; * visitor.PhoneNumber = phoneNumber; * visitor.FirstName = firstName; * visitor.LastName = lastName; * * //New Visitor..change accordingly * visitor.IsDeleted = false; * visitor.IsUpdated = false; * visitor.UpdateDatetime = startDateTime; * //visitor.LastChange = (DateTime)startDateTime; //error * visitor.LastChange = new DateTime(); * visitor.Accept = true; * visitor.AcceptUserId = 1; * visitor.Active = true; * visitor.AcceptDateTime = startDateTime; * * //Modfied accordingly * visitor.CardNeedReturn = true; * visitor.IsPhoneNrAccessUnit = false; * visitor.IsCarNrAccessUnit = false; * * _visitorRepository.Add(visitor); * * work.Commit(); * * result.Id = visitor.Id; * var entity = new VisitorEventEntity(_visitorRepository.FindById(result.Id)); * * var message = entity.GetCreateMessage(); * * // _logService.CreateLog(CurrentUser.Get().Id, "web", flag, host, CurrentUser.Get().CompanyId, message); * // _logService.CreateLog(CurrentUser.Get().Id, "web", flag, host, CurrentUser.Get().CompanyId, message); * * //_controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, user.Id, UpdateParameter.UserNameChanged, ControllerStatus.Created, string.Format("{0} {1}", user.FirstName, user.LastName)); * * // _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, visitor.Id, UpdateParameter.UserStatusChanged, ControllerStatus.Created, "Active"); * /* i19082012 * if( !string.IsNullOrEmpty(PIN1) ) * { * _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, user.Id, UpdateParameter.UserPin1Changed, ControllerStatus.Created, Encryption.Decrypt(user.PIN1)); * } * * if(!string.IsNullOrEmpty(PIN2)) * { * _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, user.Id, UpdateParameter.UserPin2Changed, ControllerStatus.Created, Encryption.Decrypt(user.PIN2)); * } * * * } * return result; * * } */ public VisitorCreateResult CreateVisitor(string carNr, int?userId, string firstName, string carType, DateTime?startDateTime, DateTime?stopDateTime, int?companyId, string lastName, string company, string email, string host, string phoneNumber, bool isphonenraccessunit, bool iscarnraccessunit, DateTime?returndate, bool iscardneedreturn, string PersonalCode, string Comment) { var result = new VisitorCreateResult { ErrorCode = UserServiceErrorCode.Ok, Id = 0 }; using (IUnitOfWork work = UnitOfWork.Begin()) { int? tc = 0; int id1 = 0; int tc1 = 0; DateTime?validto = null; IEnumerable <ClassificatorValue> cv = _classificatorValueRepository.FindByValue("Visitors"); foreach (var obj in cv) { tc = obj.Legal; id1 = obj.Id; validto = obj.ValidTo; } if (validto == null && tc == null) { result.Id = 0; } else { //tc1 = _userRepository.FindAll(x => !x.IsDeleted && x.Active == true && (x.IsShortTermVisitor == true || x.IsVisitor == true)).ToList().Count(); tc1 = _visitorRepository.FindAll(x => !x.IsDeleted && x.StopDateTime > DateTime.Now).ToList().Count(); int remaining = Convert.ToInt32(tc) - tc1; remaining = remaining < 0 ? 0 : remaining; if (remaining > 0 && validto > DateTime.Now) { Visitor visitor = DomainObjectFactory.CreateVisitor(); IFoxSecIdentity identity = CurrentUser.Get(); visitor.CarNr = carNr; if (userId == 0) { visitor.UserId = null; visitor.ParentVisitorsId = null; } else { visitor.UserId = userId; //int cardid = _usersAccessUnitRepository.FindAll(x => !x.IsDeleted && x.UserId == visitor.UserId && x.TypeId == 7 && x.Active == true && x.ValidTo < DateTime.Now).Select(x => x.Id).FirstOrDefault(); List <UsersAccessUnit> cardidlist = _usersAccessUnitRepository.FindAll(x => !x.IsDeleted && x.UserId == visitor.UserId && x.TypeId == 7 && x.Active == true).ToList(); var obj = cardidlist.FirstOrDefault(); //visitor.ParentVisitorsId = cardid; //foreach (var obj in cardidlist) //{ UsersAccessUnit carddet = _usersAccessUnitRepository.FindById(Convert.ToInt32(obj.Id)); var message2 = new XElement(XMLLogLiterals.LOG_MESSAGE); message2.Add(XMLLogMessageHelper.TemplateToXml("LogMessageCardCodeSerial", new List <string> { carddet.Serial, carddet.Serial })); message2.Add(XMLLogMessageHelper.TemplateToXml("LogMessageCardCodeDk", new List <string> { carddet.Dk, carddet.Dk })); message2.Add(XMLLogMessageHelper.TemplateToXml("LogMessageCardValidFromChanged", new List <string> { Convert.ToString(carddet.ValidFrom), Convert.ToString(startDateTime) })); message2.Add(XMLLogMessageHelper.TemplateToXml("LogMessageCardValidToChanged", new List <string> { Convert.ToString(carddet.ValidTo), Convert.ToString(stopDateTime) })); carddet.ValidFrom = startDateTime; carddet.ValidTo = stopDateTime; carddet.Closed = null; carddet.Id = obj.Id; work.Commit(); _logservice1.CreateLog(CurrentUser.Get().Id, "web", flag, host, CurrentUser.Get().CompanyId, message2.ToString()); //} _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, Convert.ToInt32(visitor.UserId), UpdateParameter.UserStatusChanged, ControllerStatus.Created, "Active"); } if (companyId == null || companyId == 0) { if (visitor.UserId != null) { companyId = _userRepository.FindById(Convert.ToInt32(visitor.UserId)).CompanyId; } } visitor.FirstName = firstName; visitor.CarType = carType; visitor.StartDateTime = startDateTime; visitor.StopDateTime = stopDateTime; visitor.CompanyId = companyId; visitor.LastName = lastName; //visitor.Company = company; visitor.ReturnDate = stopDateTime; // visitor.Email = string.IsNullOrEmpty(email) ? "" : email; //error visitor.Email = email; visitor.PhoneNumber = phoneNumber; visitor.FirstName = firstName; visitor.LastName = lastName; //New Visitor..change accordingly visitor.IsDeleted = false; visitor.IsUpdated = false; visitor.UpdateDatetime = startDateTime; //visitor.LastChange = (DateTime)startDateTime; //error visitor.LastChange = startDateTime; visitor.Accept = true; visitor.AcceptUserId = 1; visitor.Active = true; visitor.AcceptDateTime = startDateTime; //Modfied accordingly visitor.CardNeedReturn = true; visitor.IsPhoneNrAccessUnit = isphonenraccessunit; visitor.IsCarNrAccessUnit = iscarnraccessunit; visitor.CardNeedReturn = iscardneedreturn; visitor.ReturnDate = returndate; visitor.PersonalCode = PersonalCode; visitor.Comment = Comment; _visitorRepository.Add(visitor); work.Commit(); try { result.Id = visitor.Id; var entity = new VisitorEventEntity(_visitorRepository.FindById(result.Id)); var message = entity.GetCreateMessage(); _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, message.ToString()); } catch (Exception e) { Console.WriteLine("error:" + e); } } else { result.Id = 0 - Convert.ToInt32(tc); } } return(result); } }
/* public void SynchonizeUserTimeZones(int userId) * { * int[] userTimeZoneIds = (from utz in _userTimeZoneRepository.FindAll(x => !x.IsDeleted && x.UserId == userId && x.TimeZoneId.HasValue) select utz.TimeZoneId.Value).ToArray(); * int[] commonTimeZoneIds = (from tz in _timeZoneRepository.FindAll(x => !x.IsDeleted) select tz.Id).ToArray(); * int[] copyTimeZoneIds = (from id in commonTimeZoneIds where !userTimeZoneIds.Contains(id) select id).ToArray(); * string loginName = _userRepository.FindById(userId).LoginName; * * foreach (int id in copyTimeZoneIds) * { * var tz = _timeZoneRepository.FindById(id); * var createTz = true; * if( CurrentUser.Get().IsCompanyManager ) * { * var utz = tz.UserTimeZones.Where(x => !x.IsDeleted && x.IsCompanySpecific).FirstOrDefault(); * * if( utz != null ) * { * var user = _userRepository.FindById(utz.UserId); * if( user.CompanyId != CurrentUser.Get().CompanyId ) * { * createTz = false; * } * } * } * * if( createTz ) * { * using (IUnitOfWork work = UnitOfWork.Begin()) * { * UserTimeZone userTimeZone = DomainObjectFactory.CreateUserTimeZone(); * //TimeZone timeZone = new //_timeZoneRepository.FindById(id); * * userTimeZone.UserId = userId; * //userTimeZone.TimeZoneId = timeZone.Id; Edit Later * userTimeZone.ParentUserTimeZoneId = null; * //userTimeZone.Name = timeZone.Name; * userTimeZone.Uid = Guid.NewGuid(); * userTimeZone.IsOriginal = true; * userTimeZone.IsDeleted = false; * userTimeZone.IsCompanySpecific = false; * * var tzProperties = _timeZonePropertyRepository.FindAll(x => x.TimeZoneId == timeZone.Id).ToList(); * * foreach (var tzp in tzProperties) * { * UserTimeZoneProperty utzp = DomainObjectFactory.CreateUserTimeZoneProperty(); * * utzp.UserTimeZoneId = userTimeZone.Id; * utzp.TimeZoneId = tzp.TimeZoneId; * utzp.OrderInGroup = tzp.OrderInGroup; * utzp.ValidFrom = tzp.ValidFrom; * utzp.ValidTo = tzp.ValidTo; * utzp.IsMonday = tzp.IsMonday; * utzp.IsTuesday = tzp.IsTuesday; * utzp.IsWednesday = tzp.IsWednesday; * utzp.IsThursday = tzp.IsThursday; * utzp.IsFriday = tzp.IsFriday; * utzp.IsSaturday = tzp.IsSaturday; * utzp.IsSunday = tzp.IsSunday; * * userTimeZone.UserTimeZoneProperties.Add(utzp); * * var message = new XElement(XMLLogLiterals.LOG_MESSAGE); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageUTZPropertyforUTZCreated", * new List<string> {userTimeZone.Name, loginName})); * * * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageTimeZoneId", * new List<string> {utzp.TimeZoneId.ToString()})); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageOrderInGroup", * new List<string> {utzp.OrderInGroup.ToString()})); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageValidFrom", * new List<string> * { * utzp.ValidFrom.HasValue * ? utzp.ValidFrom.Value.ToString("HH:mm") * : "" * })); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageValidTo", * new List<string> * { * utzp.ValidTo.HasValue ? utzp.ValidTo.Value.ToString("HH:mm") : "" * })); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageIsMonday", new List<string> {utzp.IsMonday.ToString()})); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageIsTuesday", new List<string> {utzp.IsTuesday.ToString()})); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageIsWednesday", * new List<string> {utzp.IsWednesday.ToString()})); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageIsThursday", * new List<string> {utzp.IsThursday.ToString()})); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageIsFriday", new List<string> {utzp.IsFriday.ToString()})); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageIsSaturday", * new List<string> {utzp.IsSaturday.ToString()})); * message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageIsSunday", new List<string> {utzp.IsSunday.ToString()})); * * _logService.CreateLog(CurrentUser.Get().Id, "web", CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, * message.ToString()); * } * * _userTimeZoneRepository.Add(userTimeZone); * * work.Commit(); * * var mesage = new XElement(XMLLogLiterals.LOG_MESSAGE); * mesage.Add(XMLLogMessageHelper.TemplateToXml("LogMessageUserTimeZoneCommonCreated", * new List<string> {userTimeZone.Name, loginName})); * _logService.CreateLog(CurrentUser.Get().Id, "web", CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, mesage.ToString()); * _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, userTimeZone.Id, UpdateParameter.UserTimeZoneUpdate, ControllerStatus.Created, userTimeZone.Name); * } * } * } * } */ public int CreateUserTimeZone(string name) { using (IUnitOfWork work = UnitOfWork.Begin()) { UserTimeZone userTimeZone = DomainObjectFactory.CreateUserTimeZone(); if (CurrentUser.Get().IsCompanyManager) { UserTimeZone mtz = _userTimeZoneRepository.FindAll(x => x.CompanyId == null && x.Name == name).First(); userTimeZone.TimeZoneId = mtz.TimeZoneId; userTimeZone.CompanyId = CurrentUser.Get().CompanyId; userTimeZone.UserId = CurrentUser.Get().Id; userTimeZone.Name = name; userTimeZone.Uid = Guid.NewGuid(); userTimeZone.IsOriginal = false; userTimeZone.IsDeleted = false; userTimeZone.IsCompanySpecific = CurrentUser.Get().IsCompanyManager; var timezoneprop = (from tzp in _userTimeZonePropertyRepository.FindAll(x => x.UserTimeZoneId == mtz.Id) select tzp); for (int i = 0; i < 4; i++) { var userTimeZoneProperty = DomainObjectFactory.CreateUserTimeZoneProperty(); UserTimeZoneProperty utzp = (from tzp in timezoneprop where tzp.OrderInGroup == i select tzp).First(); userTimeZoneProperty.UserTimeZoneId = userTimeZone.Id; userTimeZoneProperty.TimeZoneId = userTimeZone.TimeZoneId; userTimeZoneProperty.OrderInGroup = i; userTimeZoneProperty.ValidFrom = utzp.ValidFrom; userTimeZoneProperty.ValidTo = utzp.ValidTo; userTimeZoneProperty.IsMonday = utzp.IsMonday; userTimeZoneProperty.IsTuesday = utzp.IsTuesday; userTimeZoneProperty.IsWednesday = utzp.IsWednesday; userTimeZoneProperty.IsThursday = utzp.IsThursday; userTimeZoneProperty.IsFriday = utzp.IsFriday; userTimeZoneProperty.IsSaturday = utzp.IsSaturday; userTimeZoneProperty.IsSunday = utzp.IsSunday; userTimeZone.UserTimeZoneProperties.Add(userTimeZoneProperty); } } else { var userTimeZoneIds = (from tz in _userTimeZoneRepository.FindAll(x => x.IsDeleted == true && x.CompanyId == null) select tz); if (userTimeZoneIds.Count() != 0) { userTimeZoneIds.First().Name = name; userTimeZoneIds.First().IsDeleted = false; } else { var maxid = (from tz in _userTimeZoneRepository.FindAll() where tz.CompanyId == null select tz.TimeZoneId).Max(); userTimeZone.CompanyId = CurrentUser.Get().IsSuperAdmin ? null : CurrentUser.Get().CompanyId; userTimeZone.UserId = CurrentUser.Get().Id; userTimeZone.Name = name; userTimeZone.Uid = Guid.NewGuid(); userTimeZone.IsOriginal = true; userTimeZone.IsDeleted = false; userTimeZone.IsCompanySpecific = CurrentUser.Get().IsSuperAdmin; if (maxid != null) { userTimeZone.TimeZoneId = maxid + 1; } else { userTimeZone.TimeZoneId = 1; } } for (int i = 0; i < 4; i++) { var validFrom = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0); var validTo = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 20, 0, 0); UserTimeZoneProperty userTimeZoneProperty = DomainObjectFactory.CreateUserTimeZoneProperty(); userTimeZoneProperty.UserTimeZoneId = userTimeZone.Id; userTimeZoneProperty.TimeZoneId = userTimeZone.TimeZoneId; userTimeZoneProperty.OrderInGroup = i; userTimeZoneProperty.ValidFrom = validFrom; userTimeZoneProperty.ValidTo = validTo; userTimeZoneProperty.IsMonday = true; userTimeZoneProperty.IsTuesday = false; userTimeZoneProperty.IsWednesday = false; userTimeZoneProperty.IsThursday = false; userTimeZoneProperty.IsFriday = false; userTimeZoneProperty.IsSaturday = false; userTimeZoneProperty.IsSunday = false; userTimeZone.UserTimeZoneProperties.Add(userTimeZoneProperty); } } _userTimeZoneRepository.Add(userTimeZone); work.Commit(); var message = new XElement(XMLLogLiterals.LOG_MESSAGE); message.Add(XMLLogMessageHelper.TemplateToXml("LogMessageUserTimeZoneCreated", new List <string> { name, CurrentUser.Get().LoginName })); _logService.CreateLog(CurrentUser.Get().Id, "web", flag, CurrentUser.Get().HostName, CurrentUser.Get().CompanyId, message.ToString()); _controllerUpdateService.CreateControllerUpdate(CurrentUser.Get().Id, userTimeZone.Id, UpdateParameter.UserTimeZoneUpdate, ControllerStatus.Created, name); return(userTimeZone.Id); } }