示例#1
0
        public async Task <IActionResult> UserCompanyInfo(int UserId)
        {
            JsonResponse <UserCompanyInfo> objResult = new JsonResponse <UserCompanyInfo>();

            try
            {
                UserCompanyInfo companyInfo = await this._companyService.getUserCompanyInfo(UserId);

                if (companyInfo != null)
                {
                    objResult.Data    = companyInfo;
                    objResult.Status  = StaticResource.SuccessStatusCode;
                    objResult.Message = StaticResource.SuccessMessage;
                    return(new OkObjectResult(objResult));
                }
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(ex);
                objResult.Data    = null;
                objResult.Status  = StaticResource.FailStatusCode;
                objResult.Message = "Exception occured";;
            }
            return(new OkObjectResult(objResult));
        }
示例#2
0
        public async Task <UserCompanyInfo> getUserCompanyInfo(int comapnayId)
        {
            try
            {
                UserCompanyInfo companyInfo = new UserCompanyInfo();
                companyInfo = await(from usercompany in this.therapistContext.UserCompany
                                    join company in this.therapistContext.Company
                                    on usercompany.CompanyId equals company.CompanyId
                                    where usercompany.CompanyId == comapnayId && usercompany.IsActive == true && usercompany.IsDeleted == false
                                    select new UserCompanyInfo
                {
                    UserCompanyGuid     = usercompany.UserCompanyGuid,
                    UserId              = usercompany.UserId,
                    CompanyId           = company.CompanyId,
                    CompanyUserNameCode = company.CompanyUserNameCode
                }).FirstOrDefaultAsync();


                return(companyInfo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static UserDutiesDataModel ToDutiesModel(this UserCompanyInfo model)
 {
     return(new UserDutiesDataModel()
     {
         Code = model.Duties?.Code,
         Name = model.Duties?.Name,
         Title = model.Title?.Name,
         TitleDate = model.TitleDate,
         IsMajorManager = model.Duties?.IsMajorManager ?? false,
         DutyTags = model.Duties?.Tags?.Split("##")
     });
 }
示例#4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="model"></param>
 /// <param name="companiesService"></param>
 /// <returns></returns>
 public static UserCompanyInfoDataModel ToCompanyModel(this UserCompanyInfo model, ICompaniesService companiesService)
 {
     return(new UserCompanyInfoDataModel()
     {
         Company = new UserCompanyDataModel()
         {
             Code = model.CompanyCode,
             Name = model.Company?.Name,
             Parent = companiesService.FindParent(model.CompanyCode)?.Name,
             CompanyTags = model.Company?.Tag?.Split("##")
         },
         Duties = model.Duties?.Name
     });
 }
示例#5
0
        public async Task <IActionResult> BulkUpload([FromForm] BulkRequest request)
        {
            JsonResponse <List <CompanyUpload> > objResult = new JsonResponse <List <CompanyUpload> >();

            try
            {
                if (ModelState.IsValid)
                {
                    //string FilePath = string.Empty;
                    string folderName  = "Upload";
                    string webRootPath = $"{Directory.GetCurrentDirectory()}{@"\wwwroot"}";
                    string newPath     = Path.Combine(webRootPath, folderName);
                    string fullPath    = Path.Combine(newPath, request.file.FileName);
                    //FilePath = Path.GetTempFileName();
                    //var fileLocation = new FileInfo(FilePath);
                    ISheet sheet;
                    string sFileExtension           = Path.GetExtension(request.file.FileName).ToLower();
                    List <CompanyUpload> listUpload = new List <CompanyUpload>();
                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        request.file.CopyTo(stream);
                        stream.Position = 0;
                        if (sFileExtension == ".xls")
                        {
                            HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats
                            sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                        }
                        else
                        {
                            XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format
                            sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                        }
                    }

                    IRow            headerRow         = sheet.GetRow(0); //Get Header Row
                    int             cellCount         = headerRow.LastCellNum;
                    UserCompanyInfo companyInfo       = new UserCompanyInfo();
                    bool            getCompanyDetails = false;
                    for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File
                    {
                        bool          isError      = false;
                        bool          isMaximumLen = false;
                        bool          isDupliacate = false;
                        CompanyUpload upload       = new CompanyUpload();
                        upload.UploadId   = 0;
                        upload.UploadGuid = System.Guid.NewGuid();
                        //upload.CompanyId = request.CompanyId;
                        //upload.CreatedBy = request.CompanyUserId;
                        upload.CreatedDate  = DateTime.UtcNow;
                        upload.ModifiedBy   = null;
                        upload.ModifiedDate = null;
                        upload.IsActive     = true;
                        upload.IsDeleted    = false;
                        IRow row = sheet.GetRow(i);
                        if (row != null)
                        {
                            if (row.GetCell(0) == null || row.GetCell(0).ToString() == "")
                            {
                                upload.FirstName = null;
                                isError          = true;
                            }
                            else
                            {
                                upload.FirstName = row.GetCell(0).ToString();
                                int leng = upload.FirstName.Length;
                                if (leng > 100)
                                {
                                    isMaximumLen = true;
                                }
                                else
                                {
                                    upload.StatusCode = (int)ErrorsEnum.NoError;
                                }
                            }
                            if (row.GetCell(1) == null || row.GetCell(1).ToString() == "")
                            {
                                upload.LastName = null;
                                isError         = true;
                            }
                            else
                            {
                                upload.LastName = row.GetCell(1).ToString();
                                int leng = upload.LastName.Length;
                                if (leng > 100)
                                {
                                    isMaximumLen = true;
                                }
                                else
                                {
                                    upload.StatusCode = (int)ErrorsEnum.NoError;
                                }
                            }
                            if (row.GetCell(2) == null || row.GetCell(2).ToString() == "")
                            {
                                upload.Email = null;
                                isError      = true;
                            }
                            else
                            {
                                bool validEmail = Regex.IsMatch(row.GetCell(2).ToString(), @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                                if (!validEmail)
                                {
                                    upload.Email = row.GetCell(2).ToString();
                                    isError      = true;;
                                }
                                var existinfile = listUpload.Find(x => x.Email == row.GetCell(2).ToString());
                                if (existinfile != null)
                                {
                                    upload.Email = row.GetCell(2).ToString();
                                    isDupliacate = true;;
                                }
                                bool exist = await this.authService.CheckEmailExist(row.GetCell(2).ToString());

                                if (exist)
                                {
                                    upload.Email = row.GetCell(2).ToString();
                                    isDupliacate = true;;
                                }
                                else
                                {
                                    upload.Email = row.GetCell(2).ToString();
                                    int leng = upload.Email.Length;
                                    if (leng > 100)
                                    {
                                        isMaximumLen = true;
                                    }
                                    upload.StatusCode = (int)ErrorsEnum.NoError;
                                }
                            }
                            if (row.GetCell(3) == null || row.GetCell(3).ToString() == "")
                            {
                                isError = true;
                            }
                            else
                            {
                                var companyId = Convert.ToInt32(row.GetCell(3).ToString());
                                if (!getCompanyDetails)
                                {
                                    companyInfo = await this._companyService.getUserCompanyInfo(companyId);
                                }
                                if (companyInfo != null)
                                {
                                    upload.CompanyId  = companyInfo.CompanyId;
                                    upload.CreatedBy  = companyInfo.UserId;
                                    getCompanyDetails = true;
                                }
                                else
                                {
                                    isError = true;
                                }
                            }
                        }
                        if (isMaximumLen)
                        {
                            upload.StatusCode = (int)ErrorsEnum.Error;
                        }
                        if (isError)
                        {
                            upload.StatusCode = (int)ErrorsEnum.Error;
                        }
                        if (isDupliacate)
                        {
                            upload.StatusCode = (int)ErrorsEnum.Duplicate;
                        }
                        if (upload.StatusCode == 1)
                        {
                            var uniquename = await this.authService.GenerateUserName(upload.UploadGuid, upload.FirstName, upload.LastName);

                            //upload.UserName = request.CompanyUserNameCode + "-" + uniquename;
                            upload.UserName     = companyInfo.CompanyUserNameCode + "-" + uniquename;
                            upload.UserPassword = this.authService.CreateRandomAlphabet();
                        }

                        if (upload.FirstName == null && upload.LastName == null && upload.Email == null)
                        {
                        }
                        else
                        {
                            listUpload.Add(upload);
                        }
                    }
                    listUpload = await this._companyService.BulkUpload(listUpload);

                    objResult.Data    = listUpload;
                    objResult.Status  = StaticResource.SuccessStatusCode;
                    objResult.Message = StaticResource.SuccessMessage;
                }
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(ex);
                objResult.Data    = null;
                objResult.Status  = StaticResource.FailStatusCode;
                objResult.Message = StaticResource.FailMessage;
            }
            return(new OkObjectResult(objResult));
        }