Exemplo n.º 1
0
        // POST
        public async Task <SingleResponse <SiteEmployee> > CreateSiteEmployeeAsync(SiteEmployee siteEmployee)
        {
            var response = new SingleResponse <SiteEmployee>();

            // Add entity to repository
            DbContext.Add(siteEmployee, UserInfo);
            // Save entity in database
            await DbContext.SaveChangesAsync();


            response.SetMessageSucssesPost(nameof(SiteEmployee), siteEmployee.SiteEmployeeId);
            // Set the entity to response model
            response.Model = siteEmployee;

            return(response);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostEmployeeAsync([FromBody] EmployeeRequest request)
        {
            if (!request.AgreeOnTheBylaws)
            {
                ModelState.AddModelError("AgreeOnTheBylaws", "Employee not Agree On The Bylaws");
            }

            var existingEntity = await EmployeeService.GetEmployeeByIdentityNumberAsync(request.IdentityNumber);

            if (existingEntity.Model != null)
            {
                ModelState.AddModelError("EmployeeIdentityNumber", "תעודת הזהות קיימת במערכת");
            }

            if (!ModelState.IsValid)
            {
                throw new Exception();
            }

            var entity = request.ToEntity();

            entity.UserInsert = UserInfo.UserId;

            var employeeResponse = await EmployeeService.CreateEmployeeAsync(entity);

            if (request.PhoneNumber != null)
            {
                PhoneMail phoneMail = new PhoneMail();
                phoneMail.PhoneNumber  = request.PhoneNumber;
                phoneMail.Email        = request.Email;
                phoneMail.EntityTypeId = (int)EntityTypeEnum.Employee;
                phoneMail.EntityId     = employeeResponse.Model.EmployeeId;

                var res = await EmployeeService.CreatePhoneMailAsync(phoneMail, typeof(Employee));

                if (res.DIdError)
                {
                    employeeResponse.SetMessageErrorCreate(nameof(PhoneMail), res.Message);
                }
            }

            if (request.ProffesionTypeId != null)
            {
                EmployeeProffesionType proffesionType = new EmployeeProffesionType();
                proffesionType.ProffesionTypeId = request.ProffesionTypeId;
                proffesionType.EmployeeId       = employeeResponse.Model.EmployeeId;

                var res = await EmployeeService.CreateEmployeeProffesionTypeAsync(proffesionType, typeof(Employee));

                if (res.DIdError)
                {
                    employeeResponse.SetMessageErrorCreate(nameof(ProffesionType), res.Message);
                }
            }

            Docs docs = new Docs();

            docs.EntityTypeId = (int)EntityTypeEnum.Employee;
            docs.EntityId     = employeeResponse.Model.EmployeeId;
            var fileName = employeeResponse.Model.IdentityNumber + "FaceImage";

            //יש לבדוק אם אכן זה עובד
            //upload picture to blob
            var DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.picture, (int)DocumentType.FaceImage);

            employeeResponse.Model.picturePath = DOCSResponse.Model.DocumentPath;
            if (DOCSResponse.DIdError)
            {
                employeeResponse.SetMessageErrorUpdate("FaceImage", DOCSResponse.Message);
            }

            docs = new Docs();
            docs.EntityTypeId = (int)EntityTypeEnum.Employee;
            docs.EntityId     = employeeResponse.Model.EmployeeId;
            fileName          = employeeResponse.Model.IdentityNumber + "CopyofID";

            DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.IdentityFile, (int)DocumentType.CopyofID);

            employeeResponse.Model.IdentityFilePath = DOCSResponse.Model.DocumentPath;
            if (DOCSResponse.DIdError)
            {
                employeeResponse.SetMessageErrorUpdate("CopyofID", DOCSResponse.Message);
            }

            docs = new Docs();
            docs.EntityTypeId = (int)EntityTypeEnum.Employee;
            docs.EntityId     = employeeResponse.Model.EmployeeId;
            fileName          = employeeResponse.Model.IdentityNumber + "CopyPassport";

            DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.PassportFile, (int)DocumentType.CopyPassport);

            employeeResponse.Model.PassportFilePath = DOCSResponse.Model.DocumentPath;
            if (DOCSResponse.DIdError)
            {
                employeeResponse.SetMessageErrorUpdate("CopyPassport", DOCSResponse.Message);
            }

            SiteEmployee siteEmployee = new SiteEmployee();

            siteEmployee.EmployeeId = employeeResponse.Model.EmployeeId;
            siteEmployee.SiteId     = request.SiteId;
            var response = await EmployeeService.CreateSiteEmployeeAsync(siteEmployee);

            return(employeeResponse.ToHttpResponse());
        }
Exemplo n.º 3
0
        public static EmployeeResponse ToEntity(this Employee request, PhoneMail phone, Docs docsFaceImage, Docs docsCopyPassport, Docs docsCopyofID, EquipmenAtSite equipmenAtSite, SiteEmployee siteEmployee, EmplyeePicture emplyeePicture = null, HealthDeclaration healthDeclaration = null)
        => new EmployeeResponse
        {
            EmployeeId = request.EmployeeId,

            IdentificationTypeId = request.IdentificationTypeId,
            IdentityNumber       = request.IdentityNumber,
            PassportCountryId    = request.PassportCountryId,
            FirstName            = request.FirstName,
            LastName             = request.LastName,
            FirstNameEn          = request.FirstNameEn,
            LastNameEn           = request.LastNameEn,
            OrganizationId       = request.OrganizationId,
            BirthDate            = request.BirthDate,
            GenderId             = request.GenderId,
            Citizenship          = request.Citizenship,
            UserInsert           = request.UserInsert,
            DateInsert           = request.DateInsert,
            UserUpdate           = request.UserUpdate,
            DateUpdate           = request.DateUpdate,
            State                  = request.State,
            Address                = request.Address,
            Gender                 = request.Gender,
            IdentificationType     = request.IdentificationType,
            Organization           = request.Organization,
            PassportCountry        = request.PassportCountry,
            EmployeeTraining       = request.EmployeeTraining.Count > 0 ? new TrainingResponse((request.EmployeeTraining.Max(x => x.DateTo).Value.Date - DateTime.Now.Date).Days, "תדריך בטיחות") : new TrainingResponse(0, "תדריך בטיחות"),
            EmployeeAuthtorization = request.EmployeeAuthtorization.Count > 0 ? new TrainingResponse((request.EmployeeAuthtorization.Max(x => x.DateTo).Value.Date - DateTime.Now.Date).Days, "אישור עבודה בגובה"): new TrainingResponse(0, "אישור עבודה בגובה"),
            EmployeeWorkPermit     = request.IdentificationTypeId == 1 || request.IdentificationTypeId == null ? new TrainingResponse(100, "היתר עבודה") :request.EmployeeWorkPermit.Count > 0 ? new TrainingResponse((request.EmployeeWorkPermit.Max(x => x.DateTo).Value.Date - DateTime.Now.Date).Days, "היתר עבודה"): new TrainingResponse(0, "היתר עבודה"),
            phonMail               = phone,
            ProffesionType         = request.EmployeeProffesionType.Count > 0? request.EmployeeProffesionType.First().ProffesionType:null,
            picturePath            = docsFaceImage == null ? null: docsFaceImage.DocumentPath,
            IdentityFilePath       = docsCopyofID == null ? null : docsCopyofID.DocumentPath,
            PassportFilePath       = docsCopyPassport == null ? null : docsCopyPassport.DocumentPath,
            isEmployeeEntry        = equipmenAtSite != null,//אם יש כניסה לאתר
            SiteId                 = siteEmployee == null ? null : siteEmployee.SiteId,
            EmployeePicture        = emplyeePicture,
            HealthDeclaration      = healthDeclaration,
            isHealthDeclaration    = healthDeclaration == null ? false : true
        };
Exemplo n.º 4
0
        public static async Task <Sites> GetSitesByEmployeeIdAsync(this MastpenBitachonDbContext dbContext, SiteEmployee entity)
        {
            var query = from site in dbContext.Sites

                        join siteEmployee in dbContext.SiteEmployee.Where(x => x.EmployeeId == entity.EmployeeId)
                        on site.SiteId equals siteEmployee.SiteId

                        select site;

            return(query.FirstOrDefault());
        }