// GET: Offer/Create public ActionResult Create() { try { if (SessionBag.Current.User != null) { SCategory scate = new SCategory(); Models.Offer offer = new Models.Offer(); offer.Categories = scate.FindAll(); //Request.Referrer.ToString() ViewBag.UrlRef = Request.UrlReferrer.LocalPath; offer.DateIniPhase1 = DateTime.Now.Date; offer.DateEndPhase1 = DateTime.Now.Date; offer.DateIniPhase2 = DateTime.Now.Date; offer.DateEndPhase2 = DateTime.Now.Date; offer.DateIniPhase3 = DateTime.Now.Date; offer.DateEndPhase3 = DateTime.Now.Date; offer.DateIniPhase4 = DateTime.Now.Date; offer.DateEndPhase4 = DateTime.Now.Date; ViewBag.IdUser = SessionBag.Current.User.Id; return(View(offer)); } else { //offerp.IdUser = "******"; return(RedirectToAction("Index", "Home")); //throw new Exception("Favor iniciar sesion con usuario y password "); } } catch (Exception er) { Log4NetLogger logger2 = new Log4NetLogger(); logger2.CurrentUser = SessionBag.Current.User.Id; if (Request != null) { logger2.Error(er, Request.Path, Request.RawUrl); throw new Exception(er.Message); } else { logger2.Error(er); } } return(RedirectToAction("Index", "Home")); }
// GET: Offer/Edit/5 public ActionResult Edit(int id) { SOffer soffer = new SOffer(); Persistence.Entities.Offer offer = soffer.GetById(id); Models.Offer offerm = new Models.Offer(); SCategory scate = new SCategory(); offerm.Categories = scate.FindAll(); offerm.InjectFrom(offer); offerm.Category = new Models.Category(); offerm.Category.InjectFrom(offer.Category); AddOfferPhasesToOffer(offer, offerm); ViewBag.UrlRef = Request.UrlReferrer.LocalPath; ViewBag.IdUser = SessionBag.Current.User.Id; return(View(offerm)); }
// GET: Project public ActionResult Index(string id) { int statusProject = 0; if (Request.QueryString["statusProject"] != null) { statusProject = int.Parse(Request.QueryString["statusProject"]); } ViewBag.Status = statusProject; SOffer soffer = new SOffer(); int pagenumber = 1; //int.Parse( Request.QueryString.Get("pagenumber")); int itemsperpage = 50; // int.Parse(Request.QueryString.Get("itemsperpage")); string conditions = ""; ZonaFl.Persistence.Entities.AspNetUsers useru = null; ZonaFl.Business.SubSystems.SUser usern = new Business.SubSystems.SUser(); useru = usern.GetUserById(new Guid(id)); if (SessionBag.Current.User == null) { SessionBag.Current.User = useru; } //if (statusProject == 2 && !useru.Freelance) // statusProject = 1; // Publicada = 0, //EnCurso = 1, //Finalizada = 2, //Eliminada = 3 if (statusProject == 0) { if (!useru.Freelance) { //conditions = " where O.Id NOT IN(SELECT Project.idoffer from project) and O.iduser='******' and (OP.StatusPhase=" + statusProject + " "; //Request.QueryString.Get("conditions"); conditions = " where O.Id NOT IN(SELECT Project.idoffer from project) and (O.iduser='******' and O.Status=0"; //and (OP.StatusPhase=" + statusProject + " "; //Request.QueryString.Get("conditions"); } else { conditions = " where O.Id NOT IN(SELECT Project.idoffer from project) and (OU.iduser='******' and O.Status=0";// and (OP.StatusPhase=" + statusProject + " "; //Request.QueryString.Get("conditions"); } } else if (statusProject >= 1) { if (!useru.Freelance) { conditions = " where O.IdUser = '******' and (project.Status = " + statusProject + " OR O.Status=" + statusProject; //conditions = " where O.Id IN(SELECT Project.idoffer from project) and (O.iduser='******' and project.Status="+ statusProject; } else { //conditions = " where O.IdUser = '******' and project.Status = " + statusProject; conditions = " where O.Id IN(SELECT Project.idoffer from project where project.Status=" + statusProject + ") and (OU.iduser='******'"; //Request.QueryString.Get("conditions"); } } ///user session bag ZonaFl.Business.SubSystems.SProject userp = new Business.SubSystems.SProject(); var projects = userp.GetProjectsEndedByUser(id); List <Models.Project> projetsm = new List <Models.Project>(); projetsm = projects.Select(e => new Models.Project().InjectFrom(e)).Cast <Models.Project>().ToList(); projetsm.Select(e => new Models.Project().InjectFrom(usern.GetUserByOffer(e.IdOffer, 1))).Cast <Models.Project>().ToList(); ViewBag.Commentaries = projetsm; int calif = userp.GetCalificationAverageUser(id); //calif = 3; ViewBag.Calification = calif; RegisterBindingModel regbm = new RegisterBindingModel(); regbm.InjectFrom(useru); regbm.Skills = useru.Skills.Select(e => new ZonaFl.Models.Skill().InjectFrom(e)).Cast <ZonaFl.Models.Skill>().ToList(); SessionBag.Current.User = regbm; ViewBag.IdUser = id; ViewBag.NameUser = regbm.UserName; ViewBag.User = useru.UserName; ViewBag.ImageUser = useru.Image; ViewBag.EmailUserBuyer = regbm.Email; ViewBag.EmailConfirmed = (useru.EmailConfirmed)? @"verified": @""; ViewBag.PagosConfirmed = (useru.PagosConfirmed) ? @"verified" : @""; // ViewBag.MobileConfirmed= ///// string order = Request.QueryString.Get("order"); SCategory scat = new SCategory(); List <ZonaFl.Persistence.Entities.Category> listcat = scat.FindAll(); ViewBag.Categories = listcat; List <Persistence.Entities.Offer> lista = new List <Persistence.Entities.Offer>(); if (!regbm.Freelance) { //if (statusProject == 0) //{ // conditions += " or OP.StatusPhase =" + 1+")"; //} //else //{ conditions += " )"; //} lista = soffer.GetListPaged(pagenumber, itemsperpage, conditions + ";", order, statusProject); } else { conditions += " )"; lista = soffer.GetAppliedOfferByUserListPaged(pagenumber, itemsperpage, conditions, order); } List <Models.Offer> listoffers = lista.Select(e => new Models.Offer().InjectFrom(e)).Cast <Models.Offer>().ToList(); SProject spro = new SProject(); listoffers.ForEach(e => e.Comments = spro.GetByOffer(e.Id) != null ? spro.GetByOffer(e.Id).Comments : ""); listoffers.ForEach(e => e.Qualification = spro.GetByOffer(e.Id) != null ? spro.GetByOffer(e.Id).Qualification : 0); if (statusProject == 1) { listoffers.ForEach(e => e.IsForFinally = spro.IsProjectForFinally(e.Id)); } List <Persistence.Entities.Category> listcategories = lista.Select(e => e.Category).ToList(); foreach (var offer in lista) { var offerget = soffer.GetById(offer.Id); if (offerget != null) { offer.OfferPhases = offerget.OfferPhases.Select(e => new Persistence.Entities.OfferPhases().InjectFrom(e)).Cast <Persistence.Entities.OfferPhases>().ToList(); } listoffers.FirstOrDefault(e => e.Id == offer.Id).OfferPhases = offer.OfferPhases.Where(e => e.IdOffer == offer.Id).ToList().Select(t => new OfferPhase().InjectFrom(t)).Cast <OfferPhase>().ToList(); //new OfferPhase().InjectFrom(e)).Cast<OfferPhase>().ToList(); //foreach(var of in offer.OfferPhases.Where(e => e.IdOffer == offer.Id).ToList()) // { // Models.OfferPhase newof = new Models.OfferPhase(); // newof.InjectFrom(of); // listoffers.FirstOrDefault(e => e.Id == offer.Id).OfferPhases.Add(newof); // } if (listoffers.FirstOrDefault(e => e.Id == offer.Id) != null) { listoffers.FirstOrDefault(e => e.Id == offer.Id).Category = new Models.Category();//.InjectFrom(offer.Category); } listoffers.FirstOrDefault(e => e.Id == offer.Id).Category.InjectFrom(offer.Category); listoffers.FirstOrDefault(e => e.Id == offer.Id).ContractorCity = ((RegisterBindingModel)SessionBag.Current.User).City; listoffers.FirstOrDefault(e => e.Id == offer.Id).ContractorCountry = ((RegisterBindingModel)SessionBag.Current.User).Country; listoffers.FirstOrDefault(e => e.Id == offer.Id).NameContractor = ((RegisterBindingModel)SessionBag.Current.User).FirstMiddleName; listoffers.FirstOrDefault(e => e.Id == offer.Id).NoPostulados = soffer.GetNoPostuladosByOffer(offer.Id); var dateoferfase1 = soffer.GetPhaseInitial(offer.Id); if (dateoferfase1 == null) { listoffers.FirstOrDefault(e => e.Id == offer.Id).DateIniPhase1 = DateTime.Parse("01/01/1900"); } else { ViewBag.InicioEst = dateoferfase1.InitPhase; if (offer.OfferPhases.Count > 0) { var finest = offer.OfferPhases.LastOrDefault(e => e.FinishPhase != null).FinishPhase; ViewBag.FinEst = finest; listoffers.FirstOrDefault(e => e.Id == offer.Id).FinEst = finest; } else { ViewBag.FinEst = dateoferfase1.FinishPhase; listoffers.FirstOrDefault(e => e.Id == offer.Id).FinEst = dateoferfase1.FinishPhase; } listoffers.FirstOrDefault(e => e.Id == offer.Id).DateIniPhase1 = dateoferfase1.InitPhase; listoffers.FirstOrDefault(e => e.Id == offer.Id).InicioEst = dateoferfase1.InitPhase; } } if (!regbm.Freelance) { return(View("DetailsForEmployer", listoffers)); } else { return(View("DetailsForFreelance", listoffers)); } }
// GET: Offer public ActionResult Index(string id) { try { SOffer soffer = new SOffer(); int pagenumber = 1; //int.Parse( Request.QueryString.Get("pagenumber")); int itemsperpage = 50; // int.Parse(Request.QueryString.Get("itemsperpage")); string conditions = ""; ///user session bag ZonaFl.Persistence.Entities.AspNetUsers useru = null; ZonaFl.Business.SubSystems.SUser usern = new Business.SubSystems.SUser(); useru = usern.GetUserById(new Guid(id)); if (SessionBag.Current.User == null) { SessionBag.Current.User = useru; } if (!useru.Freelance) { conditions = " where iduser='******'and(O.Status=0 )"; //Request.QueryString.Get("conditions"); } else { conditions = " where OP.StatusPhase<>2 and OP.StatusPhase<>3 and OP.StatusPhase<>4 AND O.Id NOT IN(SELECT Project.idoffer from project)"; //Request.QueryString.Get("conditions"); } var skills = useru.Skills.Where(e => e.CategoryId != null).ToList(); var categories = skills.GroupBy(n => n.CategoryId).ToList(); int i = 0; foreach (var cat in categories) { if (i == 0) { conditions += " and (O.CategoryId=" + cat.Key; } else { conditions += " or O.CategoryId=" + cat.Key; } i += 1; } conditions += ")"; RegisterBindingModel regbm = new RegisterBindingModel(); regbm.InjectFrom(useru); regbm.Skills = useru.Skills.Select(e => new ZonaFl.Models.Skill().InjectFrom(e)).Cast <ZonaFl.Models.Skill>().ToList(); SessionBag.Current.User = regbm; ViewBag.IdUser = id; ViewBag.User = useru.UserName; ViewBag.ImageUser = SessionBag.Current.User.Image; ///// string order = Request.QueryString.Get("order"); SCategory scat = new SCategory(); List <ZonaFl.Persistence.Entities.Category> listcat = scat.FindAll(); ViewBag.Categories = listcat; List <Persistence.Entities.Offer> lista = soffer.GetListPaged(pagenumber, itemsperpage, conditions, order); List <Models.Offer> listoffers = lista.Select(e => new Models.Offer().InjectFrom(e)).Cast <Models.Offer>().ToList(); List <Persistence.Entities.Category> listcategories = lista.Select(e => e.Category).ToList(); Dictionary <int, string> dicofferexiste = new Dictionary <int, string>(); int offeruserexist = -1; if (TempData["OfferMessage"] != null) { dicofferexiste = (Dictionary <int, string>)TempData["OfferMessage"]; offeruserexist = dicofferexiste.FirstOrDefault().Key; } foreach (var offer in lista) { var offerget = soffer.GetById(offer.Id); if (offerget != null) { offer.OfferPhases = offerget.OfferPhases.Select(e => new OfferPhases().InjectFrom(e)).Cast <OfferPhases>().ToList(); } listoffers.FirstOrDefault(e => e.Id == offer.Id).OfferPhases = offer.OfferPhases.Select(e => new OfferPhase().InjectFrom(e)).Cast <OfferPhase>().ToList(); if (listoffers.FirstOrDefault(e => e.Id == offer.Id) != null) { listoffers.FirstOrDefault(e => e.Id == offer.Id).Category = new Models.Category();//.InjectFrom(offer.Category); } listoffers.FirstOrDefault(e => e.Id == offer.Id).Category.InjectFrom(offer.Category); listoffers.FirstOrDefault(e => e.Id == offer.Id).ContractorCity = ((RegisterBindingModel)SessionBag.Current.User).City; listoffers.FirstOrDefault(e => e.Id == offer.Id).ContractorCountry = ((RegisterBindingModel)SessionBag.Current.User).Country; listoffers.FirstOrDefault(e => e.Id == offer.Id).NameContractor = ((RegisterBindingModel)SessionBag.Current.User).FirstMiddleName; listoffers.FirstOrDefault(e => e.Id == offer.Id).NoPostulados = soffer.GetNoPostuladosByOffer(offer.Id); if (offer.Id == offeruserexist) { listoffers.FirstOrDefault(e => e.Id == offer.Id).Applicada = true; } var dateoferfase1 = soffer.GetPhaseInitial(offer.Id); if (dateoferfase1 == null) { listoffers.FirstOrDefault(e => e.Id == offer.Id).DateIniPhase1 = DateTime.Parse("01/01/1900"); } else { listoffers.FirstOrDefault(e => e.Id == offer.Id).DateIniPhase1 = dateoferfase1.InitPhase; } } //listoffers.ForEach(e => e.Category.InjectFrom(listcategories.Where(i => i.Id == e.Id).FirstOrDefault())); if (((RegisterBindingModel)SessionBag.Current.User).Freelance) { return(View("DetailsForFreelance", listoffers)); } else { return(RedirectToAction("Index", "Projects", new { id = SessionBag.Current.User.Id })); } } catch (Exception er) { Log4NetLogger logger2 = new Log4NetLogger(); logger2.CurrentUser = SessionBag.Current.User.Id; if (Request != null) { logger2.Error(er, Request.Path, Request.RawUrl); } else { logger2.Error(er); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Filter(string filter) { if (!string.IsNullOrEmpty(filter) && filter.EndsWith("or ")) { filter = " and " + ReplaceLastOccurrence(filter, "or", ""); } if (!string.IsNullOrEmpty(filter) && filter.EndsWith("and ")) { filter = " and " + ReplaceLastOccurrence(filter, "and", ""); } SOffer soffer = new SOffer(); int pagenumber = 1; //int.Parse( Request.QueryString.Get("pagenumber")); int itemsperpage = 50; // int.Parse(Request.QueryString.Get("itemsperpage")); string conditions = ""; ///user session bag ZonaFl.Persistence.Entities.AspNetUsers useru = null; ZonaFl.Business.SubSystems.SUser usern = new Business.SubSystems.SUser(); string id = ((RegisterBindingModel)SessionBag.Current.User).Id; useru = usern.GetUserById(new Guid(id)); if (!useru.Freelance) { conditions = " where iduser='******' " + filter + "' and OP.StatusPhase<>2 and OP.StatusPhase<>3; "; //Request.QueryString.Get("conditions"); } else { conditions = " where OP.StatusPhase<>2 and OP.StatusPhase<>3 AND O.Id NOT IN(SELECT Project.idoffer from project) " + filter; //Request.QueryString.Get("conditions"); } //se quitan los skill porque aqui se puede haber filtrado por skills diferentes //var skills = useru.Skills.Where(e => e.CategoryId != null).ToList(); //var categories = skills.GroupBy(n => n.CategoryId).ToList(); //int i = 0; //foreach (var cat in categories) //{ // if (i == 0) // { // conditions += " and (O.CategoryId=" + cat.Key; // } // else // { // conditions += " or O.CategoryId=" + cat.Key; // } // i += 1; //} //conditions += ")"; RegisterBindingModel regbm = new RegisterBindingModel(); regbm.InjectFrom(useru); regbm.Skills = useru.Skills.Select(e => new ZonaFl.Models.Skill().InjectFrom(e)).Cast <ZonaFl.Models.Skill>().ToList(); //SessionBag.Current.User = regbm; ViewBag.IdUser = id; ///// string order = Request.QueryString.Get("order"); SCategory scat = new SCategory(); List <ZonaFl.Persistence.Entities.Category> listcat = scat.FindAll(); ViewBag.Categories = listcat; List <Persistence.Entities.Offer> lista = soffer.GetListPaged(pagenumber, itemsperpage, conditions, order); List <Models.Offer> listoffers = lista.Select(e => new Models.Offer().InjectFrom(e)).Cast <Models.Offer>().ToList(); List <Persistence.Entities.Category> listcategories = lista.Select(e => e.Category).ToList(); Dictionary <int, string> dicofferexiste = new Dictionary <int, string>(); int offeruserexist = -1; if (TempData["OfferMessage"] != null) { dicofferexiste = (Dictionary <int, string>)TempData["OfferMessage"]; offeruserexist = dicofferexiste.FirstOrDefault().Key; } foreach (var offer in lista) { var offerget = soffer.GetById(offer.Id); if (offerget != null) { offer.OfferPhases = offerget.OfferPhases.Select(e => new OfferPhases().InjectFrom(e)).Cast <OfferPhases>().ToList(); } listoffers.FirstOrDefault(e => e.Id == offer.Id).OfferPhases = offer.OfferPhases.Select(e => new OfferPhase().InjectFrom(e)).Cast <OfferPhase>().ToList(); if (listoffers.FirstOrDefault(e => e.Id == offer.Id) != null) { listoffers.FirstOrDefault(e => e.Id == offer.Id).Category = new Models.Category();//.InjectFrom(offer.Category); } listoffers.FirstOrDefault(e => e.Id == offer.Id).Category.InjectFrom(offer.Category); listoffers.FirstOrDefault(e => e.Id == offer.Id).ContractorCity = ((RegisterBindingModel)SessionBag.Current.User).City; listoffers.FirstOrDefault(e => e.Id == offer.Id).ContractorCountry = ((RegisterBindingModel)SessionBag.Current.User).Country; listoffers.FirstOrDefault(e => e.Id == offer.Id).NameContractor = ((RegisterBindingModel)SessionBag.Current.User).FirstMiddleName; if (offer.Id == offeruserexist) { listoffers.FirstOrDefault(e => e.Id == offer.Id).Applicada = true; } var dateoferfase1 = soffer.GetPhaseInitial(offer.Id); if (dateoferfase1 == null) { listoffers.FirstOrDefault(e => e.Id == offer.Id).DateIniPhase1 = DateTime.Parse("01/01/1900"); } else { listoffers.FirstOrDefault(e => e.Id == offer.Id).DateIniPhase1 = dateoferfase1.InitPhase; } } //listoffers.ForEach(e => e.Category.InjectFrom(listcategories.Where(i => i.Id == e.Id).FirstOrDefault())); if (((RegisterBindingModel)SessionBag.Current.User).Freelance) { return(PartialView("PartialFilterOffer", listoffers)); } else { return(RedirectToAction("Index", "Projects", new { id = SessionBag.Current.User.Id })); } //SOffer soffer = new SOffer(); //int pagenumber = 1;//int.Parse( Request.QueryString.Get("pagenumber")); //int itemsperpage = 50;// int.Parse(Request.QueryString.Get("itemsperpage")); //string conditions = " where iduser='******' " + filter + "; "; //Request.QueryString.Get("conditions"); //string order = Request.QueryString.Get("order"); //SCategory scat = new SCategory(); //List<ZonaFl.Persistence.Entities.Category> listcat = scat.FindAll(); //ViewBag.Categories = listcat; //List<Persistence.Entities.Offer> lista = soffer.GetListPaged(pagenumber, itemsperpage, conditions, order); //List<Models.Offer> listoffers = lista.Select(e => new Models.Offer().InjectFrom(e)).Cast<Models.Offer>().ToList(); //List<Persistence.Entities.Category> listcategories = lista.Select(e => e.Category).ToList(); //foreach (var offer in lista) //{ // if (listoffers.FirstOrDefault(e => e.Id == offer.Id) != null) // listoffers.FirstOrDefault(e => e.Id == offer.Id).Category = new Models.Category();//.InjectFrom(offer.Category); // listoffers.FirstOrDefault(e => e.Id == offer.Id).Category.InjectFrom(offer.Category); // listoffers.FirstOrDefault(e => e.Id == offer.Id).ContractorCity = ((RegisterBindingModel)SessionBag.Current.User).City; // listoffers.FirstOrDefault(e => e.Id == offer.Id).ContractorCountry = ((RegisterBindingModel)SessionBag.Current.User).Country; // listoffers.FirstOrDefault(e => e.Id == offer.Id).NameContractor = ((RegisterBindingModel)SessionBag.Current.User).FirstMiddleName; // var phase= soffer.GetPhaseInitial(offer.Id); // if (phase != null) // { // ViewBag.InicioEst = phase.InitPhase; // if(offer.OfferPhases.Count>0) // ViewBag.FinEst = offer.OfferPhases.LastOrDefault(e => e.FinishPhase != null).FinishPhase; // listoffers.FirstOrDefault(e => e.Id == offer.Id).DateIniPhase1 = soffer.GetPhaseInitial(offer.Id).InitPhase; // } // else // { // listoffers.FirstOrDefault(e => e.Id == offer.Id).DateIniPhase1 = DateTime.Parse("01/01/1900"); // } //} ////listoffers.ForEach(e => e.Category.InjectFrom(listcategories.Where(i => i.Id == e.Id).FirstOrDefault())); //if (((RegisterBindingModel)SessionBag.Current.User).Freelance) //{ // return PartialView("PartialFilterOffer", listoffers); //} //else //{ // return PartialView("PartialFilterOffer", listoffers); //} }