public void Change(Procurement oldProcurement, Procurement newProcurement)
        {
            if (!Procurements.Contains(oldProcurement))
            {
                return;
            }
            if (oldProcurement == newProcurement)
            {
                return;
            }

            procurements[procurements.IndexOf(oldProcurement)] = newProcurement;
            IsChanged = true;
            OddmentsContainer.Instance.Update();
        }
Пример #2
0
        public ActionResult PublishAdvert(string DepartmentName, List <AdvertPreparation> Adverts)
        {
            string   email    = Request.Headers["Email"];
            var      tenantId = catalog.GetTenantIDFromClientURL(email);
            DateTime dt       = DateTime.Now;

            try
            {
                if (tenantId == null)
                {
                    return(Json(new
                    {
                        success = false,
                        message = "TenantId is null",
                        data = new { }
                    }, JsonRequestBehavior.AllowGet));
                }
                var DepartmentID   = db.Department.Where(x => x.DepartmentName == DepartmentName).Select(x => x.DepartmentID).FirstOrDefault();
                int AdvertStatusID = 0;
                int.TryParse(GetConfiguration("PublishedAdvertStatusID"), out AdvertStatusID);
                foreach (AdvertPreparation Advertised in Adverts)
                {
                    var AdvertInDraft = Advertised.Category;
                    if (Adverts == null)
                    {
                        LogHelper.Log(Log.Event.Update_ADVERT, "Advert with ID: " + Advertised.AdvertID + "do not exist.");
                        Response.StatusCode = (int)HttpStatusCode.NotFound;
                        return(Error("Project with ID: " + Advertised.AdvertID + "do not exist."));
                    }
                    Adverts UpdateAdvert = db.Adverts.Find(Advertised.AdvertID);
                    UpdateAdvert.AdvertStatusID             = AdvertStatusID;
                    UpdateAdvert.Headline                   = Advertised.Headline;
                    UpdateAdvert.Introduction               = Advertised.Introduction;
                    UpdateAdvert.ScopeOfWork                = Advertised.ScopeOfWork;
                    UpdateAdvert.EligibiltyRequirement      = Advertised.EligibiltyRequirement;
                    UpdateAdvert.CollectionOfTenderDocument = Advertised.CollectionOfTenderDocument;
                    UpdateAdvert.BidSubmission              = Advertised.BidSubmission;
                    UpdateAdvert.OtherImportantInformation  = Advertised.BidSubmission;
                    UpdateAdvert.BidOpeningDate             = Advertised.BidOpeningDate;
                    UpdateAdvert.BidClosingDate             = Advertised.BidClosingDate;
                    UpdateAdvert.DateModified               = dt;
                    db.Entry(UpdateAdvert).State            = EntityState.Modified;
                    var DeleteProject = Advertised.Category.Where(x => x.Deleted == true);
                    if (Advertised.Category != null)
                    {
                        foreach (var AdvertCategory in DeleteProject)
                        {
                            db.AdvertLotNumber.RemoveRange(db.AdvertLotNumber.Where(x => x.ProcurementID == AdvertCategory.ProcurementID));
                        }
                    }
                    foreach (AdvertProjectCategory draftAdvert in AdvertInDraft)
                    {
                        var getProjectCategoryID = db.ProjectCategory.Where(x => x.ProjectCategoryID == draftAdvert.ProjectCategoryID).Select(x => x.ProjectCategoryID).FirstOrDefault();
                        var getProjectCategory   = db.ProjectCategory.Where(x => x.ProjectCategoryID == draftAdvert.ProjectCategoryID).Select(x => x.Name).FirstOrDefault();
                        var getAdvertCategoryID  = db.AdvertCategory.Where(x => x.AdvertCategory1 == getProjectCategory).Select(x => x.AdvertCategoryID).FirstOrDefault();

                        if (Advertised.AdvertID == Guid.Empty && draftAdvert.ProcurementID == Guid.Empty)
                        {
                            LogHelper.Log(Log.Event.Update_ADVERT, "Advert OR Procurement ID could not be found.");
                            Response.StatusCode = (int)HttpStatusCode.BadRequest;
                            return(Error("Advert OR Procurement ID could not be found."));
                        }
                        var getAdvertLotNumberID      = db.AdvertLotNumber.Where(x => x.ProcurementID == draftAdvert.ProcurementID).Select(x => x.AdvertLotNumberID).FirstOrDefault();
                        var getAdvertCategoryNumberID = db.AdvertCategoryNumber.Where(x => x.ProjectCategoryID == draftAdvert.ProjectCategoryID).Select(x => x.AdvertCategoryNumberID).FirstOrDefault();

                        AdvertLotNumber advertLotNumber = db.AdvertLotNumber.Find(getAdvertLotNumberID);
                        advertLotNumber.LotCode         = draftAdvert.CategoryLotCode;
                        advertLotNumber.DateModified    = dt;
                        db.Entry(advertLotNumber).State = EntityState.Modified;

                        AdvertCategoryNumber advertCategoryNumber = db.AdvertCategoryNumber.Find(getAdvertCategoryNumberID);
                        advertCategoryNumber.CategoryLotCode   = draftAdvert.CategoryLotCode;
                        advertCategoryNumber.ProjectCategoryID = getProjectCategoryID;
                        advertCategoryNumber.AdvertCategoryID  = getAdvertCategoryID;
                        advertCategoryNumber.DateModified      = dt;
                        db.Entry(advertCategoryNumber).State   = EntityState.Modified;

                        Procurements procurements = db.Procurements.Find(draftAdvert.ProcurementID);
                        procurements.ProjectName     = draftAdvert.ProjectName;
                        procurements.DateModified    = dt;
                        db.Entry(procurements).State = EntityState.Modified;

                        db.SaveChanges();
                    }
                }
                return(PutAdvertJson());
            }
            catch (Exception ex)
            {
                LogHelper.Log(Log.Event.PUBLISHED_ADVERT, ex.Message);
                return(Json(new
                {
                    success = false,
                    message = "" + ex.Message,
                    data = new { }
                }, JsonRequestBehavior.AllowGet));
            }
        }