Exemplo n.º 1
0
        public int AddJobOffer(string Title, string CompanyName, decimal Salary, string Description, string ContactName,
                               string PhoneNumber, string Email, HttpPostedFile Logo, string Url, string Address, int CategoryId,
                               string CountryCode, int PositionId, bool Status, string ExpiryDate)
        {
            try
            {
                JobsDS ds = new JobsDS();
                lw.Jobs.JobsDSTableAdapters.JobOffersTableAdapter Adp = new lw.Jobs.JobsDSTableAdapters.JobOffersTableAdapter();
                JobsDS.JobOffersDataTable dt  = new JobsDS.JobOffersDataTable();
                JobsDS.JobOffersRow       row = dt.NewJobOffersRow();

                DateTime date;

                row.Title        = Title;
                row.CompanyName  = CompanyName;
                row.Salary       = Salary;
                row.Description  = Description;
                row.ContactName  = ContactName;
                row.PhoneNumber  = PhoneNumber;
                row.Email        = Email;
                row.Url          = Url;
                row.Address      = Address;
                row.CategoryId   = CategoryId;
                row.CountryCode  = CountryCode;
                row.PositionId   = PositionId;
                row.Status       = Status;
                row.CreationDate = DateTime.Now;
                row.ModifiedDate = DateTime.Now;
                if (DateTime.TryParse(ExpiryDate, out date))
                {
                    row.ExpiryDate = date;
                }

                dt.AddJobOffersRow(row);
                Adp.Update(dt);

                int jobOfferId = row.Id;


                JobOffersAdp adp = new JobOffersAdp();
                if (Logo != null && Logo.ContentLength > 0)
                {
                    Config cfg = new Config();

                    string path     = WebContext.Server.MapPath("~/" + lw.CTE.Folders.JobLogos);
                    string ext      = StringUtils.GetFileExtension(Logo.FileName);
                    string fileName = StringUtils.GetFriendlyFileName(Logo.FileName);

                    string _imageName = string.Format("{0}_{1}.{2}",
                                                      fileName, jobOfferId, ext);

                    string imageName = string.Format("{0}\\{1}", path, _imageName);

                    Logo.SaveAs(imageName);

                    if (cfg.GetKey("JobLogo") == "on")
                    {
                        try
                        {
                            int _Width  = Int32.Parse(cfg.GetKey("JobLogoWidth"));
                            int _Height = Int32.Parse(cfg.GetKey("JobLogoHeight"));

                            ImageUtils.Resize(imageName, imageName, _Width, _Height);
                            adp.UpdateLogo(_imageName, jobOfferId);
                        }
                        catch (IOException Ex)
                        {
                            this.UpdateError("IO ERROR, Could not save job offer logo: <br />" + Ex.Message);
                        }
                        catch (Exception ex1)
                        {
                            throw ex1;
                        }
                    }
                    else
                    {
                        try
                        {
                            adp.UpdateLogo(_imageName, jobOfferId);
                            Logo.SaveAs(Path.Combine(path, _imageName));
                        }
                        catch (IOException Ex)
                        {
                            this.UpdateError("IO ERROR, Could not save job offer logo: <br />" + Ex.Message);
                        }
                        catch (Exception ex1)
                        {
                            throw ex1;
                        }
                    }
                }
                return(jobOfferId);
            }
            catch (Exception Ex)
            {
                this.UpdateError("Fail to add job: <br />" + Ex.Message);
                return(-1);
            }
        }
Exemplo n.º 2
0
        public void UpdateJobOffer(int JobOfferId, string Title, string CompanyName, decimal Salary, string Description,
                                   string ContactName, string PhoneNumber, string Email, HttpPostedFile Logo, string Url, string Address,
                                   int CategoryId, string CountryCode, int PositionId, bool Status, string ExpiryDate, bool DeleteLogo)
        {
            try
            {
                JobOffersAdp        adp = new JobOffersAdp();
                JobsDS.JobOffersRow row = (JobsDS.JobOffersRow)GetJobOffers(string.Format("Id={0}", JobOfferId)).Rows[0];

                DateTime date;

                row.Title        = Title;
                row.CompanyName  = CompanyName;
                row.Salary       = Salary;
                row.Description  = Description;
                row.ContactName  = ContactName;
                row.PhoneNumber  = PhoneNumber;
                row.Email        = Email;
                row.Url          = Url;
                row.Address      = Address;
                row.CategoryId   = CategoryId;
                row.CountryCode  = CountryCode;
                row.PositionId   = PositionId;
                row.Status       = Status;
                row.ModifiedDate = DateTime.Now;
                if (DateTime.TryParse(ExpiryDate, out date))
                {
                    row.ExpiryDate = date;
                }
                else
                {
                    row.ExpiryDate = DateTime.MaxValue;
                }

                adp.Update(row);

                string path = WebContext.Server.MapPath("~/" + lw.CTE.Folders.JobLogos);

                string fileName = "";

                DeleteLogo = (DeleteLogo || (Logo != null && Logo.ContentLength > 0)) &&
                             row["Logo"].ToString() != "";

                if (DeleteLogo)
                {
                    fileName = Path.Combine(path, row["Logo"].ToString());
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                    adp.UpdateLogo("", JobOfferId);
                }

                if (Logo != null && Logo.ContentLength > 0)
                {
                    Config cfg = new Config();

                    string ext = StringUtils.GetFileExtension(Logo.FileName);
                    fileName = StringUtils.GetFriendlyFileName(Logo.FileName);

                    string _imageName = string.Format("{0}_{1}.{2}",
                                                      fileName, JobOfferId, ext);

                    string imageName = string.Format("{0}\\{1}", path, _imageName);

                    Logo.SaveAs(imageName);

                    if (cfg.GetKey("JobLogo") == "on")
                    {
                        try
                        {
                            int _Width  = Int32.Parse(cfg.GetKey("JobLogoWidth"));
                            int _Height = Int32.Parse(cfg.GetKey("JobLogoHeight"));

                            ImageUtils.Resize(imageName, imageName, _Width, _Height);
                            adp.UpdateLogo(_imageName, JobOfferId);
                        }
                        catch (IOException Ex)
                        {
                            this.UpdateError("IO ERROR, Could not save job offer logo: <br />" + Ex.Message);
                        }
                        catch (Exception ex1)
                        {
                            throw ex1;
                        }
                    }
                    else
                    {
                        try
                        {
                            adp.UpdateLogo(_imageName, JobOfferId);
                            Logo.SaveAs(Path.Combine(path, _imageName));
                        }
                        catch (IOException Ex)
                        {
                            this.UpdateError("IO ERROR, Could not save job offer logo: <br />" + Ex.Message);
                        }
                        catch (Exception ex1)
                        {
                            throw ex1;
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                this.UpdateError("Fail to update job offer: <br />" + Ex.Message);
            }
        }