Пример #1
0
        public void InsertLicencePathintbl(int id)
        {
            using (IUnitOfWork work = UnitOfWork.Begin())
            {
                IEnumerable <ClassificatorValue> cv = _classificatorValueRepository.FindByValue("Licence Path");

                if (cv.ToList().Count == 0)
                {
                    ClassificatorValue cv1 = DomainObjectFactory.CreateClassificatorValue();

                    cv1.ClassificatorId = id;
                    cv1.Value           = "Licence Path";
                    cv1.SortOrder       = 8;
                    _classificatorValueRepository.Add(cv1);
                    work.Commit();
                }
            }
        }
Пример #2
0
        public ActionResult Add(CompanyEditViewModel cevm)
        {
            int?     tc      = 0;
            int      id1     = 0;
            int      tc1     = 0;
            DateTime?validto = null;

            IEnumerable <ClassificatorValue> cv = _classificatorValueRepository.FindByValue("Companies");

            foreach (var obj in cv)
            {
                tc      = obj.Legal;
                id1     = obj.Id;
                validto = obj.ValidTo;
            }
            if (validto == null && tc == null)
            {
                return(Json(new
                {
                    IsSucceed = false,
                    Msg = "licence error",
                    Count = 0
                }));
            }
            else
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("select count(distinct CompanyId) from users where IsDeleted=0 and CompanyId is not null and id in (select UserId from uSERROLES where IsDeleted=0 and RoleId in (select id from Roles where IsDeleted=0 and RoleTypeId=3))", con);
                tc1 = Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();

                int remaining = Convert.ToInt32(tc) - tc1;
                remaining = remaining < 0 ? 0 : remaining;
                if (remaining > 0 && validto > DateTime.Now)
                {
                    int    id  = 0;
                    string err = string.Empty;
                    if (cevm.Company.CompanyBuildingItems.Any(x => x.BuildingId == null))
                    {
                        ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesEmptyBuildingSelected);
                    }
                    if (cevm.Company.CompanyBuildingItems.Any(x => x.BuildingId != null && !x.CompanyFloors.Any(cf => cf.IsSelected)))
                    {
                        ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesNoBuildingSelectedMessage);
                    }

                    var build_ids = GetUserBuildings(_buildingRepository, _userRepository);
                    if (build_ids.Any(x => cevm.Company.CompanyBuildingItems.Where(cb => cb.BuildingId == x).Count() > 1))
                    {
                        ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesEqualBildingsErrorMessage);
                    }

                    var building_items = new List <SelectListItem>();

                    Mapper.Map(_buildingRepository.FindAll().Where(x => build_ids.Contains(x.Id)), building_items);

                    foreach (var cbi in cevm.Company.CompanyBuildingItems)
                    {
                        cbi.BuildingItems = building_items;
                    }

                    if (ModelState.IsValid)
                    {
                        try
                        {
                            IEnumerable <CompanyBuildingDto> company_buildings = GetSelectedCompanyBuildings(cevm.Company);
                            id = _companyService.CreateCompany(cevm.Company.Name, cevm.Company.Comment, cevm.Company.IsCanUseOwnCards, HostName, company_buildings);
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", ex.Message);
                            err = ex.Message;
                        }
                    }
                    if (id < 0)
                    {
                        return(Json(new { IsSucceed = false }));
                    }
                    else
                    {
                        var complist = _companyRepository.FindAll().Where(x => x.IsDeleted == false && x.Active == true && x.ParentId == null).OrderBy(y => y.Name).ToList();
                        cevm.CompanyItems = complist;
                        return(Json(new
                        {
                            IsSucceed = ModelState.IsValid,
                            Id = id,
                            Msg = ModelState.IsValid ? ViewResources.SharedStrings.DataSavingMessage : err,
                            viewData = ModelState.IsValid ? string.Empty : this.RenderPartialView("Create", cevm)
                        }));
                    }
                }
                else
                {
                    return(Json(new
                    {
                        IsSucceed = false,
                        Msg = "licence error",
                        Count = tc
                    }));
                }
            }
        }
Пример #3
0
        /* 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);
            }
        }