public bool Create(BCModel.Projects.Project entity)
        {
            try
            {
                if (validateEntity(entity))
                {
                    _repo.Create(entity);
                    _repo.Save();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                ValidationDic.Clear();
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        ValidationDic.Add(validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
                return false;
            }
            catch (Exception ex)
            {

                ValidationDic.Clear();
                ValidationDic.Add("exception", ex.Message);
                return false;
            }
        }
示例#2
0
        public ActionResult DeleteConfirmed(string id)
        {
            BCModel bCModel = db.BCModels.Find(id);

            db.BCModels.Remove(bCModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
 public ActionResult Edit([Bind(Include = "codeBC,date_emission,quantite,codeU,codeDEPOT,date_c")] BCModel bCModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bCModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bCModel));
 }
示例#4
0
        public ActionResult Create([Bind(Include = "codeBC,date_emission,quantite,codeU,codeDEPOT,date_c")] BCModel bCModel)
        {
            if (ModelState.IsValid)
            {
                db.BCModels.Add(bCModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bCModel));
        }
示例#5
0
        // GET: BCModels/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BCModel bCModel = db.BCModels.Find(id);

            if (bCModel == null)
            {
                return(HttpNotFound());
            }
            return(View(bCModel));
        }
 public bool Delete(BCModel.Projects.Invitation entity)
 {
     try
     {
         _repo.Delete(entity);
         _repo.Save();
         return true;
     }
     catch (Exception ex)
     {
         ValidationDic.Clear();
         ValidationDic.Add("Exception", ex.Message);
         return false;
     }
 }
示例#7
0
 public bool Create(BCModel.Scope entity)
 {
     try
     {
         _repo.Create(entity);
         _repo.Save();
         return true;
     }
     catch (Exception ex)
     {
         ValidationDic.Clear();
         ValidationDic.Add("exception", ex.Message);
         return false;
     }
 }
 public bool CreateCompany(BCModel.CompanyProfile company)
 {
     try
     {
         _repo.CreateCompany(company);
         _repo.Save();
         return true;
     }
     catch (Exception ex)
     {
         ValidationDic.Clear();
         ValidationDic.Add("exception", ex.Message);
         return false;
     }
 }
 public bool Delete(BCModel.CompanyProfile entity)
 {
     try
     {
         _repo.Delete(entity);
         _repo.Save();
         return true;
     }
     catch (Exception ex)
     {
         ValidationDic.Clear();
         ValidationDic.Add("exception", ex.Message);
         return false;
     }
 }
示例#10
0
 public bool DeleteComputedBid(BCModel.Projects.ComputedBid bid)
 {
     try
     {
         _repo.DeleteComputedBid(bid);
         _repo.Save();
         return true;
     }
     catch (Exception ex)
     {
         ValidationDic.Clear();
         ValidationDic.Add("Exception", ex.Message);
         return false;
     }
 }
示例#11
0
        public bool AddNetworkConnection(BCModel.SocialNetwork.ContactConnection connection)
        {
            try
            {

                if (validateConnection(connection))
                {
                    _repo.AddNetworkConnection(connection);
                    _repo.SaveChanges();
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                ValidationDic.Clear();
                ValidationDic.Add("Exception", ex.Message);
                return false;
            }
        }
示例#12
0
 public bool SendNetworkRequest(BCModel.SocialNetwork.ContactRequest request)
 {
     try
     {
         if (validateNewRequest(request))
         {
             _repo.AddNetworkRequest(request);
             _repo.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception ex)
     {
         ValidationDic.Clear();
         ValidationDic.Add("Exception", ex.Message);
         return false;
     }
 }
 public void Delete(BCModel.Notification entity)
 {
     _notes.Remove(entity);
 }
 public void Create(BCModel.Notification entity)
 {
     _notes.Add(entity);
 }
 public void Create(BCModel.CompanyProfile entity)
 {
     _companies.Add(entity);
 }
示例#16
0
 public void Delete(BCModel.Projects.ProjectDocument entity)
 {
     _docs.Remove(entity);
 }
示例#17
0
        private bool validateEntity(BCModel.Projects.Project entity)
        {
            bool valid = true;
            ValidationDic.Clear();

            var results = (from r in _repo.Query()
                           where r.ArchitectId == entity.ArchitectId
                           && r.Number == entity.Number
                           && r.Title == entity.Title
                           && r.CreatedById == entity.CreatedById
                           select r);

            if (results.Count() > 0)
            {
                valid = false;
                ValidationDic.Add("Duplicate", "You have already created this project");
            }

            // TODO: add more validation logic

            return valid;
        }
示例#18
0
        /// <summary>
        /// sends an internal notification to a user
        /// </summary>
        /// <param name="recipientId">userid</param>
        /// <param name="notificationType">type of notification</param>
        /// <param name="projectId">the project the notification is for</param>
        /// <returns></returns>
        public bool SendNotification(int recipientId, RecipientType recipientType, BCModel.NotificationType notificationType, int entityId, EntityType entityType)
        {
            try
            {
                switch (recipientType)
                {
                    // if company, then loop through each of the companies users
                    case RecipientType.company:
                        List<Notification> existingNotices = (from r in _repo.Query()
                                                              where r.NotificationType == notificationType      // notification type y
                                                              && r.Recipient.CompanyId == recipientId                     // sent to company z
                                                              && r.EntityId == entityId                       // for project x
                                                              && r.EntityType == entityType
                                                              && !r.Read                                        // not read yet
                                                              && EntityFunctions.DiffDays(r.LastEditTimestamp, DateTime.Now).Value == 0  // from today
                                                              select r).ToList();
                        List<UserProfile> users = _repo.QueryUserProfiles().Where(x => x.CompanyId == recipientId).ToList();

                        if (existingNotices.Count == users.Count) // if there is an unread notice for each user of comany z
                        {
                            appendExistingNotices(existingNotices.ToArray());
                            _repo.Save(); // save changes
                            return true;
                        }
                        else if (existingNotices.Count > 0 && existingNotices.Count < users.Count) // if some users have read the notice already
                        {
                            // update unread
                            appendExistingNotices(existingNotices.ToArray());

                            // create new notices
                            sendNewNotices(users.Where(x => !existingNotices.Select(e => e.RecipientId).Contains(x.UserId)).Select(s => s.UserId).ToArray(), notificationType, entityId, entityType);

                            // save changes
                            _repo.Save();
                            return true;
                        }
                        else // else no notices exist
                        {
                            // create new notices
                            sendNewNotices(users.Select(s => s.UserId).ToArray(), notificationType, entityId, entityType);
                            _repo.Save();
                            return true;
                        }

                    // if user, only do the single notice
                    case RecipientType.user:
                        // find out if there is already a notification type for this project from today
                        Notification existingNotice = (from r in _repo.Query()
                                                       where r.NotificationType == notificationType      // notification type y
                                                       && r.RecipientId == recipientId                     // sent to user z
                                                       && r.EntityId == entityId                       // for project x
                                                       && r.EntityType == entityType
                                                       && !r.Read                                        // not read yet
                                                       && r.LastEditTimestamp.Date == DateTime.Now.Date  // from today
                                                       select r).SingleOrDefault();

                        // if there is not an existing notice
                        if (existingNotice != null)
                        {
                            // pull the notice out of the list
                            existingNotice.Count = existingNotice.Count++;      // increase notice count
                            existingNotice.LastEditTimestamp = DateTime.Now;    // reset timestamp
                            _repo.Update(existingNotice);                       // update notice
                            _repo.Save();                                       // save changes
                            return true;
                        }
                        else // there is no existing notice
                        {
                            Notification theNotice = new Notification
                            {
                                Count = 1,
                                LastEditTimestamp = DateTime.Now,
                                NotificationType = notificationType,
                                EntityId = entityId,
                                EntityType = entityType,
                                Read = false,
                                RecipientId = recipientId
                            };                      // draft the notice
                            _repo.Create(theNotice);    // add to queue
                            _repo.Save();               // send/save
                            return true;
                        }
                    default:
                        throw new ArgumentException("Unknown notification type");
                }

            }
            catch (Exception)
            {
                return false;
            }
        }
        public bool validateBidPackage(BCModel.Projects.BidPackage bp)
        {
            bool valid = true;
            //List<BCModel.Projects.BidPackage> bidPackages = (from r in _repo.Query()
            //                                                where r.ProjectId == bp.ProjectId
            //                                                && r.CreatedById == bp.CreatedById
            //                                                && r.Id != bp.Id
            //                                                select r).ToList();

            return valid;
        }
        public bool Update(BCModel.Projects.BidPackage entity)
        {
            try
            {
                _repo.Update(entity);
                _repo.Save();
                return true;
            }
            catch (Exception ex)
            {

                ValidationDic.Clear();
                ValidationDic.Add("Exception", ex.Message);
                return false;
            }
        }
示例#21
0
 public void DeleteNetworkConnection(BCModel.SocialNetwork.ContactConnection entity)
 {
     _conns.Remove(entity);
 }
示例#22
0
 public void AddNetworkRequest(BCModel.SocialNetwork.ContactRequest entity)
 {
     _reqs.Add(entity);
 }
示例#23
0
 public void AddNetworkConnection(BCModel.SocialNetwork.ContactConnection entity)
 {
     _conns.Add(entity);
 }
        public IEnumerable<BCModel.CompanyProfile> SearchCompanyProfiles(string query, BCModel.BusinessType[] types)
        {
            var results = from c in _repo.Query()
                          where types.Contains(c.BusinessType) &&
                          (c.CompanyName.Contains(query)
                          || c.City.Contains(query)
                          || c.PostalCode.Contains(query))
                          select c;

            return results.AsEnumerable();
        }
示例#25
0
 public void Create(BCModel.Projects.ProjectDocument entity)
 {
     _docs.Add(entity);
 }
        public IEnumerable<BCModel.CompanyProfile> SearchCompanyProfiles(BCModel.BusinessType[] types, int[] scopes)
        {
            var results = from c in _repo.Query()
                          where types.Contains(c.BusinessType) &&
                          c.Scopes.Any(s => scopes.Contains(s.ScopeId))
                          select c;

            return results.AsEnumerable();
        }
示例#27
0
 public void Update(BCModel.Projects.ProjectDocument entity)
 {
     var current = _docs.Find(entity.Id);
     _context.Entry<ProjectDocument>(current).CurrentValues.SetValues(entity);
 }
 public void Delete(BCModel.CompanyProfile entity)
 {
     _companies.Remove(entity);
 }
        public IEnumerable<BCModel.CompanyProfile> SearchCompanyProfiles(BCModel.BusinessType[] types, string city, string state, string postal, double distance)
        {
            // call up the locator
            GeoLocator locator = new GeoLocator();

            // get a search point
            DbGeography searchPoint = locator.GetFromAddress("", city, state, postal);

            var results = from c in _repo.Query()
                          where types.Contains(c.BusinessType)
                          && (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= distance
                          select c;

            return results.AsEnumerable();
        }
示例#30
0
 public void Create(BCModel.Projects.Project entity)
 {
     _projects.Add(entity);
 }
        public IEnumerable<BCModel.CompanyProfile> SearchCompanyProfiles(BCModel.BusinessType[] types, int projectEntityId, ProjectEntityType type)
        {
            IEnumerable<CompanyProfile> result;
            GeoLocator locator = new GeoLocator(); // call up the locator
            BidPackage theBp;
            DbGeography searchPoint;
            int projectIdforLocation = 0;

            switch (type)
            {
                case ProjectEntityType.bidPackage:

                    theBp = _repo.FindBidPackage(projectEntityId);
                    projectIdforLocation = theBp.ProjectId;

                    searchPoint = _repo.FindProject(projectIdforLocation).GeoLocation;

                    int[] bpScopes = theBp.Scopes.Where(s => s.Scope.Children == null).Select(s => s.ScopeId).ToArray();

                    result = from c in _repo.Query()
                             where c.Scopes.Any(s => bpScopes.Contains(s.ScopeId))
                             && types.Contains(c.BusinessType)
                             && (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= c.OperatingDistance
                             select c;

                    return result.ToList();

                case ProjectEntityType.project:

                    projectIdforLocation = projectEntityId;

                    searchPoint = _repo.FindProject(projectIdforLocation).GeoLocation;

                    result = from c in _repo.Query()
                             where (c.GeoLocation.Distance(searchPoint).Value * 0.00062137) <= c.OperatingDistance
                             && types.Contains(c.BusinessType)
                             select c;

                    return result.ToList();

                default:
                    throw new Exception("unknown entity type");
            }
        }
示例#32
0
 public void Delete(BCModel.Projects.Project entity)
 {
     _projects.Remove(entity);
 }
 public void Update(BCModel.Notification entity)
 {
     var current = _notes.Find(entity.Id);
     _context.Entry<Notification>(current).CurrentValues.SetValues(entity);
 }
 public void Update(BCModel.CompanyProfile entity)
 {
     var current = _companies.Find(entity.Id);
     _context.Entry<CompanyProfile>(current).CurrentValues.SetValues(entity);
 }