コード例 #1
0
        /// <summary>
        /// Delete User Action Activity Log
        /// </summary>
        /// <param name=></param>
        /// <returns>bool</returns>
        public async Task <bool> DeleteCompanyIndustry(int CompanyIndustryId)
        {
            #region Declare a return type with initial value.
            bool isCompanyIndustryDeleted = default(bool);
            #endregion
            try
            {
                if (CompanyIndustryId > default(int))
                {
                    #region Vars
                    CompanyIndustry CompanyIndustry = null;
                    #endregion
                    #region Get CompanyIndustry by id
                    CompanyIndustry = await UnitOfWork.CompanyIndustryRepository.GetById(CompanyIndustryId);

                    #endregion
                    #region check if object is not null
                    if (CompanyIndustry != null)
                    {
                        CompanyIndustry.IsDeleted = (byte)DeleteStatusEnum.Deleted;
                        #region Apply the changes to the database
                        UnitOfWork.CompanyIndustryRepository.Update(CompanyIndustry);
                        isCompanyIndustryDeleted = await UnitOfWork.Commit() > default(int);

                        #endregion
                    }
                    #endregion
                }
            }
            catch (Exception exception)
            {
            }
            return(isCompanyIndustryDeleted);
        }
コード例 #2
0
        public async Task <Result <int> > Handle(CreateCompanyCommand request, CancellationToken cancellationToken)
        {
            var id = _authenticatedUser.Username;

            CreatePlaceCommand place = new CreatePlaceCommand {
                PlaceName = request.PlaceName, ProvinceId = request.ProvinceId, DistrictId = request.DistrictId, CommuneId = request.CommuneId, PlaceTypeId = 23, Latitude = request.Latitude, Longitude = request.Longitude
            };
            var itemPlace = _mapper.Map <Place>(place);

            await _placeRepository.InsertAsync(itemPlace);

            await _unitOfWork.Commit(cancellationToken);

            CultureInfo provider = CultureInfo.InvariantCulture;

            //DateTime? DateOfIssue = null;
            //try { DateOfIssue = DateTime.ParseExact(request.DateOfIssueStr, "dd/MM/yyyy", provider); } catch { }
            //try { DateOfIssue = DateTime.ParseExact(request.DateOfIssueStr, "dd/MM/yyyy", provider); } catch { }

            var item = _mapper.Map <Company>(request);

            // item.DateOfIssue = DateOfIssue;
            item.PlaceId  = itemPlace.Id;
            item.UserName = id;

            await _repository.InsertAsync(item);

            await _unitOfWork.Commit(cancellationToken);


            if (request.Industries != null)
            {
                foreach (var _item in request.Industries)
                {
                    try
                    {
                        CompanyIndustry tmp = new CompanyIndustry {
                            IndustryId = _item, CompanyId = item.Id
                        };
                        await _companyIndustryRepository.InsertAsync(tmp);
                    }
                    catch
                    {
                    }
                }
            }

            return(Result <int> .Success(item.Id));
        }
コード例 #3
0
 /// <summary>
 /// Mapping User Activity Log DTO to Action
 /// </summary>
 /// <param name=></param>
 /// <param name=></param>
 /// <returns></returns>
 public CompanyIndustry MappingCompanyIndustryupdateDTOToCompanyIndustry(CompanyIndustry companyIndustry, CompanyIndustryUpdateDTO CompanyIndustryUpdateDTO)
 {
     #region Declare Return Var with Intial Value
     CompanyIndustry CompanyIndustry = companyIndustry;
     #endregion
     try
     {
         if (CompanyIndustryUpdateDTO.CompanyIndustryId > default(int))
         {
             CompanyIndustry.IndustryId           = CompanyIndustryUpdateDTO.IndustryId;
             CompanyIndustry.CompanyIndustryId    = CompanyIndustryUpdateDTO.CompanyIndustryId;
             CompanyIndustry.CompanyInformationId = CompanyIndustryUpdateDTO.CompanyInformationId;
         }
     }
     catch (Exception exception) { }
     return(CompanyIndustry);
 }
コード例 #4
0
 /// <summary>
 /// Mapping user Action Actitvity Log
 /// </summary>
 /// <param name=></ param >
 /// <returns>Task<CompanyIndustry></returns>
 public CompanyIndustry MappingCompanyIndustryAddDTOToCompanyIndustry(CompanyIndustryAddDTO CompanyIndustryAddDTO)
 {
     #region Declare a return type with initial value.
     CompanyIndustry CompanyIndustry = null;
     #endregion
     try
     {
         CompanyIndustry = new CompanyIndustry
         {
             IndustryId           = CompanyIndustryAddDTO.IndustryId,
             CompanyInformationId = CompanyIndustryAddDTO.CompanyInformationId,
             CreationDate         = DateTime.Now,
             IsDeleted            = (byte)DeleteStatusEnum.NotDeleted
         };
     }
     catch (Exception exception) { }
     return(CompanyIndustry);
 }
コード例 #5
0
        /// <summary>
        /// Get user Action Activity Log By Id
        /// </summary>
        /// <returns>List<CompanyIndustryReturnDTO></returns>
        public async Task <CompanyIndustryReturnDTO> GetCompanyIndustryById(int CompanyIndustryId)
        {
            #region Declare a return type with initial value.
            CompanyIndustryReturnDTO CompanyIndustry = new CompanyIndustryReturnDTO();
            #endregion
            try
            {
                CompanyIndustry companyIndustry = await UnitOfWork.CompanyIndustryRepository.GetById(CompanyIndustryId);

                if (companyIndustry != null)
                {
                    if (companyIndustry.IsDeleted != (byte)DeleteStatusEnum.Deleted)
                    {
                        CompanyIndustry = CompanyIndustryMapping.MappingCompanyIndustryToCompanyIndustryReturnDTO(companyIndustry);
                    }
                }
            }
            catch (Exception exception)
            {
            }
            return(CompanyIndustry);
        }
コード例 #6
0
        /// <summary>
        /// Create User Action Activity Log
        /// </summary>
        /// <param name=></param>
        /// <returns>bool</returns>
        public async Task <bool> AddCompanyIndustry(CompanyIndustryAddDTO CompanyIndustryAddDTO)
        {
            #region Declare a return type with initial value.
            bool isCompanyIndustryCreated = default(bool);
            #endregion
            try
            {
                #region Vars
                CompanyIndustry CompanyIndustry = null;
                #endregion
                CompanyIndustry = CompanyIndustryMapping.MappingCompanyIndustryAddDTOToCompanyIndustry(CompanyIndustryAddDTO);
                if (CompanyIndustry != null)
                {
                    await UnitOfWork.CompanyIndustryRepository.Insert(CompanyIndustry);

                    isCompanyIndustryCreated = await UnitOfWork.Commit() > default(int);
                }
            }
            catch (Exception exception)
            {
            }
            return(isCompanyIndustryCreated);
        }
コード例 #7
0
        /// <summary>
        /// Update User Action Activity Log
        /// </summary>
        /// <param name=></param>
        /// <returns>bool</returns>
        public async Task <bool> UpdateCompanyIndustry(CompanyIndustryUpdateDTO CompanyIndustryUpdateDTO)
        {
            #region Declare a return type with initial value.
            bool isCompanyIndustryUpdated = default(bool);
            #endregion
            try
            {
                if (CompanyIndustryUpdateDTO != null)
                {
                    #region Vars
                    CompanyIndustry CompanyIndustry = null;
                    #endregion
                    #region Get Activity By Id
                    CompanyIndustry = await UnitOfWork.CompanyIndustryRepository.GetById(CompanyIndustryUpdateDTO.CompanyIndustryId);

                    #endregion
                    if (CompanyIndustry != null)
                    {
                        #region  Mapping
                        CompanyIndustry = CompanyIndustryMapping.MappingCompanyIndustryupdateDTOToCompanyIndustry(CompanyIndustry, CompanyIndustryUpdateDTO);
                        #endregion
                        if (CompanyIndustry != null)
                        {
                            #region  Update Entity
                            UnitOfWork.CompanyIndustryRepository.Update(CompanyIndustry);
                            isCompanyIndustryUpdated = await UnitOfWork.Commit() > default(int);

                            #endregion
                        }
                    }
                }
            }
            catch (Exception exception)
            {
            }
            return(isCompanyIndustryUpdated);
        }
コード例 #8
0
        public APIGatewayProxyResponse SaveCompany(APIGatewayProxyRequest request, ILambdaContext context)
        {
            try
            {
                context.Logger.LogLine("Get Request\n");

                if (!ValidateRequest(request))
                {
                    return(new APIGatewayProxyResponse
                    {
                        StatusCode = (int)HttpStatusCode.Forbidden,
                        Headers = new Dictionary <string, string> {
                            { "Content-Type", "text/plain" }
                        }
                    });
                }

                if (string.IsNullOrEmpty(request.Body))
                {
                    throw new ArgumentNullException("request.Body");
                }

                Company source = JsonConvert.DeserializeObject <Company>(request.Body);

                Company       targetCompany;
                SilverContext silverContext = new SilverContext();
                if (!source.Id.HasValue || source.Id == 0)
                {
                    targetCompany = new Company();
                    silverContext.Companies.Add(targetCompany);
                }
                else
                {
                    targetCompany = silverContext.Companies.Where(x => x.Id == source.Id)
                                    .Include(x => x.CompanyCountries)
                                    .Include(x => x.CompanyExtendedData)
                                    .Include(x => x.CompanyQuestionnaires)
                                    .Include(x => x.CompanyIndustries)
                                    .Include(x => x.CompanyNames)
                                    .FirstOrDefault();

                    if (targetCompany == null)
                    {
                        throw new ArgumentOutOfRangeException("company");
                    }
                }

                targetCompany.Lei          = source.Lei;
                targetCompany.Status       = source.Status;
                targetCompany.LegalName    = source.LegalName;
                targetCompany.NumEmployees = source.NumEmployees;

                // countries

                var srcIds = source.CompanyCountries
                             .Where(x => x.CompanyCountryId.HasValue)
                             .Select(x => x.CompanyCountryId.Value)
                             .ToHashSet();

                var toRemove = new List <CompanyCountry>();
                foreach (var companyCountry in targetCompany.CompanyCountries)
                {
                    if (!srcIds.Contains(companyCountry.CompanyCountryId.Value))
                    {
                        toRemove.Add(companyCountry);
                    }
                }
                foreach (var item in toRemove)
                {
                    targetCompany.CompanyCountries.Remove(item);
                    silverContext.Remove(item);
                }

                foreach (var companyCountry in source.CompanyCountries)
                {
                    CompanyCountry targetEntity;
                    if (!companyCountry.CompanyCountryId.HasValue)
                    {
                        targetEntity = new CompanyCountry()
                        {
                            Company = targetCompany
                        };

                        targetCompany.CompanyCountries.Add(targetEntity);
                        silverContext.CompanyCountries.Add(targetEntity);
                    }
                    else
                    {
                        targetEntity = targetCompany.CompanyCountries.First(x => x.CompanyCountryId == companyCountry.CompanyCountryId);
                    }
                    targetEntity.CountryId         = companyCountry.CountryId;
                    targetEntity.IsPrimary         = companyCountry.IsPrimary;
                    targetEntity.LegalJurisdiction = companyCountry.LegalJurisdiction;
                    targetEntity.Ticker            = companyCountry.Ticker;
                }

                // extended data
                if (source.CompanyExtendedData.Count > 0)
                {
                    var sourceExtendedData = source.CompanyExtendedData.First();
                    CompanyExtendedData targetExtendedData;
                    if (targetCompany.CompanyExtendedData.Any())
                    {
                        targetExtendedData = targetCompany.CompanyExtendedData.First();
                    }
                    else
                    {
                        targetExtendedData = new CompanyExtendedData();
                        targetCompany.CompanyExtendedData.Add(targetExtendedData);
                        silverContext.Add(targetExtendedData);
                    }
                    targetExtendedData.BelowNationalAvgIncome = sourceExtendedData.BelowNationalAvgIncome;
                    targetExtendedData.Company           = targetCompany;
                    targetExtendedData.DisabledEmployees = sourceExtendedData.DisabledEmployees;
                    targetExtendedData.HierarchyLevel    = sourceExtendedData.HierarchyLevel;
                    targetExtendedData.RetentionRate     = sourceExtendedData.RetentionRate;
                    targetExtendedData.MedianSalary      = sourceExtendedData.MedianSalary;
                }
                else
                {
                    targetCompany.CompanyExtendedData.Clear();
                }

                // questions
                if (source.CompanyQuestionnaires.Count > 0)
                {
                    srcIds = source.CompanyQuestionnaires
                             .Where(x => x.Id.HasValue)
                             .Select(x => x.Id.Value)
                             .ToHashSet();

                    var questionsToRemove = new List <CompanyQuestion>();
                    foreach (var companyQuestion in targetCompany.CompanyQuestionnaires)
                    {
                        if (!srcIds.Contains(companyQuestion.Id.Value))
                        {
                            questionsToRemove.Add(companyQuestion);
                        }
                    }
                    foreach (var item in questionsToRemove)
                    {
                        targetCompany.CompanyQuestionnaires.Remove(item);
                        silverContext.Remove(item);
                    }

                    foreach (var companyQuestion in source.CompanyQuestionnaires)
                    {
                        CompanyQuestion targetEntity;
                        if (!companyQuestion.Id.HasValue)
                        {
                            targetEntity = new CompanyQuestion()
                            {
                                Company = targetCompany
                            };

                            targetCompany.CompanyQuestionnaires.Add(targetEntity);
                            silverContext.CompanyQuestionnaires.Add(targetEntity);
                        }
                        else
                        {
                            targetEntity = targetCompany.CompanyQuestionnaires.First(x => x.Id == companyQuestion.Id);
                        }
                        targetEntity.Question = companyQuestion.Question;
                        targetEntity.Answer   = companyQuestion.Answer;
                    }
                }
                else
                {
                    targetCompany.CompanyQuestionnaires.Clear();
                }

                // names
                if (source.CompanyNames.Count > 0)
                {
                    srcIds = source.CompanyNames
                             .Where(x => x.Id.HasValue)
                             .Select(x => x.Id.Value)
                             .ToHashSet();

                    var namesToRemove = new List <CompanyName>();
                    foreach (var companyName in targetCompany.CompanyNames)
                    {
                        if (!srcIds.Contains(companyName.Id.Value))
                        {
                            namesToRemove.Add(companyName);
                        }
                    }
                    foreach (var item in namesToRemove)
                    {
                        targetCompany.CompanyNames.Remove(item);
                        silverContext.Remove(item);
                    }

                    foreach (var companyName in source.CompanyNames)
                    {
                        CompanyName targetEntity;
                        if (!companyName.Id.HasValue)
                        {
                            targetEntity = new CompanyName()
                            {
                                Company = targetCompany
                            };

                            targetCompany.CompanyNames.Add(targetEntity);
                            silverContext.CompanyNames.Add(targetEntity);
                        }
                        else
                        {
                            targetEntity = targetCompany.CompanyNames.First(x => x.Id == companyName.Id);
                        }
                        targetEntity.Name = companyName.Name;
                        targetEntity.Type = companyName.Type;
                    }
                }
                else
                {
                    targetCompany.CompanyNames.Clear();
                }

                // industries
                if (source.CompanyIndustries.Count > 0)
                {
                    srcIds = source.CompanyIndustries
                             .Where(x => x.Id.HasValue)
                             .Select(x => x.Id.Value)
                             .ToHashSet();

                    var industriesToRemove = new List <CompanyIndustry>();
                    foreach (var companyName in targetCompany.CompanyIndustries)
                    {
                        if (!srcIds.Contains(companyName.Id.Value))
                        {
                            industriesToRemove.Add(companyName);
                        }
                    }
                    foreach (var item in industriesToRemove)
                    {
                        targetCompany.CompanyIndustries.Remove(item);
                        silverContext.Remove(item);
                    }

                    foreach (var companyIndustry in source.CompanyIndustries)
                    {
                        CompanyIndustry targetEntity;
                        if (!companyIndustry.Id.HasValue)
                        {
                            targetEntity = new CompanyIndustry()
                            {
                                Company = targetCompany
                            };

                            targetCompany.CompanyIndustries.Add(targetEntity);
                            silverContext.CompanyIndustries.Add(targetEntity);
                        }
                        else
                        {
                            targetEntity = targetCompany.CompanyIndustries.First(x => x.Id == companyIndustry.Id);
                        }
                        targetEntity.IndustryId       = companyIndustry.IndustryId;
                        targetEntity.PrimarySecondary = companyIndustry.PrimarySecondary;
                    }
                }
                else
                {
                    targetCompany.CompanyIndustries.Clear();
                }

                // TODO: roles and people

                silverContext.SaveChanges();

                var response = new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.OK,
                    Headers    = new Dictionary <string, string> {
                        { "Content-Type", "text/plain" }
                    }
                };

                return(response);
            }
            catch (Exception ex)
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Body = $"Bad query: {ex}",
                    Headers = new Dictionary <string, string> {
                        { "Content-Type", "text/plain" }
                    }
                });
            }
        }
コード例 #9
0
        public async Task <Result <int> > Handle(UpdateCompanyCommand command, CancellationToken cancellationToken)
        {
            var userName = _authenticatedUser.Username;
            var user     = await _userManager.FindByNameAsync(userName);

            var rolesList = await _userManager.GetRolesAsync(user).ConfigureAwait(false);

            var item = await _repository.GetByIdAsync(command.Id);

            if (item == null || !(rolesList.Contains("Admin") || rolesList.Contains("SuperAdmin") || userName == item.UserName))
            {
                return(Result <int> .Fail($"Lỗi!"));
            }
            else
            {
                CultureInfo provider = CultureInfo.InvariantCulture;

                /* DateTime? DateOfIssue = item.DateOfIssue;
                 * try { DateOfIssue = DateTime.ParseExact(command.DateOfIssueStr, "dd/MM/yyyy", provider); } catch { }*/

                //var placeCount = _placeRepository.Places.Where(e => e.PlaceTypeId == 23 && e.ProvinceId == command.ProvinceId && e.DistrictId == command.DistrictId && e.CommuneId == command.CommuneId && e.PlaceName == command.PlaceName ).Count();

                var place = item.Place;
                place.PlaceName  = command.PlaceName ?? place.PlaceName;
                place.ProvinceId = command.ProvinceId ?? place.ProvinceId;
                place.DistrictId = command.DistrictId ?? place.DistrictId;
                place.Latitude   = command.Latitude ?? place.Latitude;
                place.Longitude  = command.Longitude ?? place.Longitude;


                /*if (placeCount < 1)
                 * {
                 *  Place place = new Place { PlaceName = command.PlaceName, ProvinceId = command.ProvinceId, DistrictId = command.DistrictId, CommuneId = command.CommuneId, PlaceTypeId = 23, Latitude = (double)command.Latitude, Longitude = (double)command.Longitude };
                 *  await _placeRepository.InsertAsync(place);
                 *  await _unitOfWork.Commit(cancellationToken);
                 *  placeId = place.Id;
                 * }*/

                item.Name = command.Name ?? item.Name;
                item.InternationalName = command.InternationalName ?? item.InternationalName;
                item.ShortName         = command.ShortName ?? item.ShortName;
                item.TaxCode           = command.TaxCode ?? item.TaxCode;
                item.Representative    = command.Representative ?? item.Representative;
                item.PhoneNumber       = command.PhoneNumber ?? item.PhoneNumber;
                item.Website           = command.Website ?? item.Website;
                item.ProfileVideo      = command.ProfileVideo ?? item.ProfileVideo;
                item.Fax         = command.Fax ?? item.Fax;
                item.Email       = command.Email ?? item.Email;
                item.Images      = command.Images ?? item.Images;
                item.Image       = command.Image ?? item.Image;
                item.Logo        = command.Logo ?? item.Logo;
                item.CompanySize = command.CompanySize ?? item.CompanySize;
                item.Description = command.Description ?? item.Description;
                item.DateOfIssue = command.DateOfIssue ?? item.DateOfIssue;
                //item.PlaceId = placeId;

                await _repository.UpdateAsync(item);


                var item_CompanyIndustries = item.CompanyIndustries;
                foreach (var item_ in item_CompanyIndustries)
                {
                    await _companyIndustryRepository.DeleteAsync(item_);
                }

                if (command.Industries != null)
                {
                    foreach (var _item in command.Industries)
                    {
                        try
                        {
                            CompanyIndustry tmp = new CompanyIndustry {
                                IndustryId = _item, CompanyId = item.Id
                            };
                            await _companyIndustryRepository.InsertAsync(tmp);
                        }
                        catch
                        {
                        }
                    }
                }



                await _unitOfWork.Commit(cancellationToken);

                return(Result <int> .Success(item.Id));
            }
        }
コード例 #10
0
 public async Task UpdateAsync(CompanyIndustry item)
 {
     await _repository.UpdateAsync(item);
 }
コード例 #11
0
        public async Task <int> InsertAsync(CompanyIndustry item)
        {
            await _repository.AddAsync(item);

            return(item.Id);
        }
コード例 #12
0
 public async Task DeleteAsync(CompanyIndustry item)
 {
     await _repository.DeleteAsync(item);
 }
コード例 #13
0
 public CompanyIndustryReturnDTO MappingCompanyIndustryToCompanyIndustryReturnDTO(CompanyIndustry CompanyIndustry)
 {
     #region Declare a return type with initial value.
     CompanyIndustryReturnDTO CompanyIndustryReturnDTO = null;
     #endregion
     try
     {
         if (CompanyIndustry != null)
         {
             CompanyIndustryReturnDTO = new CompanyIndustryReturnDTO
             {
                 CompanyIndustryId    = CompanyIndustry.CompanyIndustryId,
                 IndustryId           = CompanyIndustry.IndustryId,
                 CompanyInformationId = CompanyIndustry.CompanyInformationId
             };
         }
     }
     catch (Exception exception)
     { }
     return(CompanyIndustryReturnDTO);
 }
コード例 #14
0
        public async Task <ActionResult> Edit(FormCollection collection)
        {
            if (Session["user_type"].Equals("GST") || Session["user_type"].Equals("STD"))
            {
                return(RedirectToAction("../Home/Index"));
            }

            bool          flag = false;
            CompanyRegErr err  = new CompanyRegErr();

            ViewBag.Industries = db.IndustryLists;
            Company c = new Company();

            if (string.IsNullOrEmpty(Request.Form["id"]) || !Session["user_id"].Equals(Request.Form["id"]))
            {
                return(RedirectToAction("../Home/Index"));
            }
            else
            {
                c.Id = Request.Form["id"];
            }

            if (string.IsNullOrWhiteSpace(Request.Form["cname"]) && !string.IsNullOrWhiteSpace(Request.Form["gname"]))
            {
                c.Name = Request.Form["gname"];
            }
            else if (!string.IsNullOrWhiteSpace(Request.Form["cid"]))
            {
                c.GoogleId = Request.Form["cid"];
                c.Name     = Request.Form["cname"];
            }
            else
            {
                flag     = true;
                err.Name = "Company Name required";
            }

            if (string.IsNullOrWhiteSpace(Request.Form["about"]))
            {
                flag      = true;
                err.About = "You must write something about your company";
            }
            else
            {
                c.About = Request.Form["about"];
            }

            if (string.IsNullOrWhiteSpace(Request.Form["cid"]))
            {
                c.Verified = false;
            }
            else
            {
                c.Verified = true;
            }

            c.CompanyType = Request.Form["type"];
            if (!string.IsNullOrWhiteSpace(Request.Form["industry"]))
            {
                foreach (string s in Request.Form["industry"].Split(','))
                {
                    CompanyIndustry tempc = new CompanyIndustry();
                    tempc.I_Id = Convert.ToInt32(s);
                    tempc.Time = System.DateTime.Now;
                    c.CompanyIndustries.Add(tempc);
                }
            }

            HttpPostedFileBase logo = Request.Files["logo"];

            if ((logo != null) && (logo.ContentLength > 0) && !string.IsNullOrWhiteSpace(logo.FileName))
            {
                byte[] logoBytes = new byte[logo.ContentLength];
                logo.InputStream.Read(logoBytes, 0, Convert.ToInt32(logo.ContentLength));
                c.Logo = logoBytes;
            }


            if (flag)
            {
                return(View(err));
            }


            try
            {
                string response = "";

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);

                    client.DefaultRequestHeaders.Clear();

                    //Define request data format
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    //Sending request to find web api REST service resource GetAllEmployees using HttpClient

                    HttpResponseMessage Res = await client.PutAsJsonAsync("api/companiesAPI/", c);

                    //Checking the response is successful or not which is sent using HttpClient
                    if (Res.IsSuccessStatusCode)
                    {
                        //Storing the response details recieved from web api
                        var CompanyResponse = Res.Content.ReadAsStringAsync().Result;

                        //Deserializing the response recieved from web api and storing into the Employee list
                        response = JsonConvert.DeserializeObject <string>(CompanyResponse);
                    }
                }


                return(RedirectToAction("../Company/Details/" + Session["user_id"]));
            }
            catch
            {
                return(View(err));
            }
        }
コード例 #15
0
        public async Task <ActionResult> Create(FormCollection collection)
        {
            if (Session["user_type"].Equals("CMP") || Session["user_type"].Equals("STD"))
            {
                return(RedirectToAction("../Home/Index"));
            }
            bool          flag = false;
            CompanyRegErr err  = new CompanyRegErr();

            ViewBag.Industries = db.IndustryLists;
            Company c = new Company();

            if (string.IsNullOrWhiteSpace(Request.Form["cname"]) && !string.IsNullOrWhiteSpace(Request.Form["gname"]))
            {
                c.Name = Request.Form["gname"];
            }
            else if (!string.IsNullOrWhiteSpace(Request.Form["cid"]))
            {
                c.GoogleId = Request.Form["cid"];
                c.Name     = Request.Form["cname"];
            }
            else
            {
                flag     = true;
                err.Name = "Company Name required";
            }
            if (string.IsNullOrWhiteSpace(Request.Form["about"]))
            {
                flag      = true;
                err.About = "You must write something about your company";
            }
            else
            {
                c.About = Request.Form["about"];
            }

            if (string.IsNullOrWhiteSpace(Request.Form["cid"]))
            {
                c.Verified = false;
            }
            else
            {
                c.Verified = true;
            }
            c.Email       = Request.Form["email"];
            c.Password    = Request.Form["password"];
            c.CompanyType = Request.Form["type"];
            if (!string.IsNullOrWhiteSpace(Request.Form["industry"]))
            {
                foreach (string s in Request.Form["industry"].Split(','))
                {
                    CompanyIndustry tempc = new CompanyIndustry();
                    tempc.I_Id = Convert.ToInt32(s);
                    tempc.Time = System.DateTime.Now;
                    c.CompanyIndustries.Add(tempc);
                }
            }

            HttpPostedFileBase logo = Request.Files["logo"];

            if ((logo != null) && (logo.ContentLength > 0) && !string.IsNullOrWhiteSpace(logo.FileName))
            {
                byte[] logoBytes = new byte[logo.ContentLength];
                logo.InputStream.Read(logoBytes, 0, Convert.ToInt32(logo.ContentLength));
                c.Logo = logoBytes;
            }

            c.WebsiteURL = Request.Form["website"];

            err.c = c;

            if (string.IsNullOrWhiteSpace(c.Email) || !Regex.IsMatch(c.Email, @"\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))
            {
                flag      = true;
                err.Email = "Email Cannot be empty. It should be a valid email address.";
            }

            if (string.IsNullOrWhiteSpace(c.Name))
            {
                flag     = true;
                err.Name = "Company Name Cannot be Empty";
            }
            if (string.IsNullOrWhiteSpace(c.Password))
            {
                flag         = true;
                err.Password = "******";
            }
            if (!c.Password.Equals(Request.Form["repassword"]))
            {
                flag           = true;
                err.RePassword = "******";
            }
            if (string.IsNullOrWhiteSpace(c.About))
            {
                flag      = true;
                err.About = "You must write something about the company";
            }


            if (flag)
            {
                return(View(err));
            }


            try
            {
                string response = "";

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);

                    client.DefaultRequestHeaders.Clear();

                    //Define request data format
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    //Sending request to find web api REST service resource GetAllEmployees using HttpClient

                    HttpResponseMessage Res = await client.PostAsJsonAsync("api/companiesAPI/", c);

                    //Checking the response is successful or not which is sent using HttpClient
                    if (Res.IsSuccessStatusCode)
                    {
                        //Storing the response details recieved from web api
                        var CompanyResponse = Res.Content.ReadAsStringAsync().Result;

                        //Deserializing the response recieved from web api and storing into the Employee list
                        response = JsonConvert.DeserializeObject <string>(CompanyResponse);
                    }
                }

                if (response.Equals("email exists"))
                {
                    err.Email = "This Email Id Already Exists";
                    return(View(err));
                }
                else
                {
                    Session["user_type"] = "CMP";
                    Session["user_id"]   = response;
                    return(RedirectToAction("../Home/Index"));
                }
            }
            catch
            {
                return(View(err));
            }
        }