コード例 #1
0
        public void DeleteScientificName(ScientificName scientificNameToBeDeleted)
        {
            //Validate Input
            if (scientificNameToBeDeleted == null)
            {
                throw (new ArgumentNullException("scientificNameToBeDeleted"));
            }

            // Validate Primary key value
            if (scientificNameToBeDeleted.ScientificNameID.IsInvalidKey())
            {
                BusinessLayerHelper.ThrowErrorForInvalidDataKey("ScientificNameID");
            }

            OnScientificNameSaving(scientificNameToBeDeleted);
            OnScientificNameDeleting(scientificNameToBeDeleted);

            if (scientificNameToBeDeleted.EntityState == EntityState.Detached)
            {
                _DatabaseContext.ScientificNames.Attach(scientificNameToBeDeleted);
            }
            _DatabaseContext.ScientificNames.DeleteObject(scientificNameToBeDeleted);
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No ScientificName deleted!");
            }

            OnScientificNameDeleted(scientificNameToBeDeleted);
            OnScientificNameSaved(scientificNameToBeDeleted);
        }
コード例 #2
0
        public virtual int CreateNewScientificName(ScientificName newScientificName)
        {
            // Validate Parameters
            if (newScientificName == null)
            {
                throw (new ArgumentNullException("newScientificName"));
            }

            // Apply business rules
            OnScientificNameSaving(newScientificName);
            OnScientificNameCreating(newScientificName);

            _DatabaseContext.ScientificNames.AddObject(newScientificName);
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No scientificName created!");
            }

            // Apply business workflow
            OnScientificNameCreated(newScientificName);
            OnScientificNameSaved(newScientificName);

            return(newScientificName.ScientificNameID);
        }
コード例 #3
0
        public void UpdateScientificName(ScientificName updatedScientificName)
        {
            // Validate Parameters
            if (updatedScientificName == null)
            {
                throw (new ArgumentNullException("updatedScientificName"));
            }

            // Validate Primary key value
            if (updatedScientificName.ScientificNameID.IsInvalidKey())
            {
                BusinessLayerHelper.ThrowErrorForInvalidDataKey("ScientificNameID");
            }

            // Apply business rules
            OnScientificNameSaving(updatedScientificName);
            OnScientificNameUpdating(updatedScientificName);

            //attaching and making ready for parsistance
            if (updatedScientificName.EntityState == EntityState.Detached)
            {
                _DatabaseContext.ScientificNames.Attach(updatedScientificName);
            }
            _DatabaseContext.ObjectStateManager.ChangeObjectState(updatedScientificName, System.Data.EntityState.Modified);            //this line makes the code un-testable!
            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows == 0)
            {
                throw new DataNotUpdatedException("No scientificName updated!");
            }

            //Apply business workflow
            OnScientificNameUpdated(updatedScientificName);
            OnScientificNameSaved(updatedScientificName);
        }
コード例 #4
0
        public void DeleteScientificNames(List <int> scientificNameIDsToDelete)
        {
            //Validate Input
            foreach (int scientificNameID in scientificNameIDsToDelete)
            {
                if (scientificNameID.IsInvalidKey())
                {
                    BusinessLayerHelper.ThrowErrorForInvalidDataKey("ScientificNameID");
                }
            }

            List <ScientificName> scientificNamesToBeDeleted = new List <ScientificName>();

            foreach (int scientificNameID in scientificNameIDsToDelete)
            {
                ScientificName scientificName = new ScientificName {
                    ScientificNameID = scientificNameID
                };
                _DatabaseContext.ScientificNames.Attach(scientificName);
                _DatabaseContext.ScientificNames.DeleteObject(scientificName);
                scientificNamesToBeDeleted.Add(scientificName);
                OnScientificNameDeleting(scientificName);
            }

            int numberOfAffectedRows = _DatabaseContext.SaveChanges();

            if (numberOfAffectedRows != scientificNameIDsToDelete.Count)
            {
                throw new DataNotUpdatedException("One or more scientificName records have not been deleted.");
            }
            foreach (ScientificName scientificNameToBeDeleted in scientificNamesToBeDeleted)
            {
                OnScientificNameDeleted(scientificNameToBeDeleted);
            }
        }
コード例 #5
0
 public IActionResult EditName(int id, ScientificName scientific)
 {
     if (id != scientific.Id)
     {
         return(ViewBag.Message = "Invalid Id");
     }
     _db.EditName(scientific);
     return(RedirectToAction(nameof(GetScientificNames)));
 }
コード例 #6
0
        public void EditName(ScientificName scientific)
        {
            var newName = _db.ScientificNames.Where(c => c.Id == scientific.Id).FirstOrDefault();

            newName.Name      = scientific.Name;
            newName.UpdatedOn = DateTime.Now;

            _db.SaveChanges();
        }
コード例 #7
0
        public string AddName(ScientificName scientific)
        {
            scientific.CreatedOn = DateTime.Now;
            scientific.UpdatedOn = DateTime.Now;
            _db.ScientificNames.Add(scientific);
            _db.SaveChanges();
            var sucess = "Sucess";

            return(sucess);
        }
コード例 #8
0
    protected void formViewScientificName_DataBinding(object sender, EventArgs e)
    {
        string scientificNameID = Page.RouteData.Values["ScientificName_id"] as string;

        if (scientificNameID != null && scientificNameID != "0")
        {
            ScientificName scientificName = new ScientificNameBLL().GetScientificNameByScientificNameID(Convert.ToInt32(scientificNameID));
            this.editor         = new Eisk.BusinessLogicLayer.UserBLL().GetUserByUserID(scientificName.EditorUserID);
            this.creator        = new Eisk.BusinessLogicLayer.UserBLL().GetUserByUserID(scientificName.CreatorUserID);
            this.scientificName = scientificName;
        }
    }
コード例 #9
0
        public IActionResult AddScientificNames(ScientificName scientific)
        {
            var name = _db.GetColors().FindAll(a => a.Name == scientific.Name).Count();

            if (name == 0)
            {
                _db.AddName(scientific);
                return(RedirectToAction(nameof(GetScientificNames)));
            }
            ViewBag.Message = "already exists";
            return(View());
        }
コード例 #10
0
        public ScientificName GetScientificNameByScientificNameId2(int scientificNameID)
        {
            //Validate Input
            if (scientificNameID.IsInvalidKey())
            {
                BusinessLayerHelper.ThrowErrorForInvalidDataKey("scientificNameID");
            }
            ScientificName scientificName = (_DatabaseContext.ScientificNames.FirstOrDefault(instance => instance.ScientificNameID == scientificNameID));

            // var ass = scientificName.ScientificNameCreator.UserName;
            return(scientificName);
        }
コード例 #11
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = TaxonId;
         hashCode = (hashCode * 397) ^ (ScientificName != null ? ScientificName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (CommonName != null ? CommonName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SearchMatchName != null ? SearchMatchName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Category != null ? Category.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Author != null ? Author.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (NameCategory != null ? NameCategory.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)TaxonStatus;
         return(hashCode);
     }
 }
コード例 #12
0
ファイル: Tree.cs プロジェクト: galehouse5/TreesDb
        public virtual bool ShouldMerge(Tree otherTree)
        {
            if (!CommonName.Equals(otherTree.CommonName, StringComparison.OrdinalIgnoreCase) ||
                !ScientificName.Equals(otherTree.ScientificName, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (!Coordinates.IsSpecified || !otherTree.Coordinates.IsSpecified ||
                !Coordinates.Equals(otherTree.Coordinates))
            {
                return(false);
            }

            return(true);
        }
コード例 #13
0
    protected void FormViewScientificName_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        TextBox txtScientificName         = (TextBox)formViewScientificName.FindControl("txtScientificName");
        ScientificNameActionStatus status = Validate(txtScientificName.Text, actionType.update);

        if (status == ScientificNameActionStatus.Success)
        {
            Type           myType = (typeof(ScientificName));
            PropertyInfo[] props  = myType.GetProperties();

            string[] arrNewValues = new string[e.NewValues.Keys.Count];
            e.NewValues.Keys.CopyTo(arrNewValues, 0);

            ScientificNameBLL scientificNameBLL = new ScientificNameBLL();
            ScientificName    scientificName    = scientificNameBLL.GetScientificNameByScientificNameId2((int)e.Keys["ScientificNameId"]);

            foreach (var prop in props)
            {
                if (("System.String,System.Int,System.DateTime,System.Guid").IndexOf((prop.PropertyType).FullName) >= 0) // Si la propiedad es de tipo Guid, String, Int o DateTime
                {
                    if (!arrNewValues.Contains(prop.Name))
                    {
                        e.NewValues[prop.Name] = prop.GetValue(scientificName, null);
                    }
                }
            }

            User editor = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name);

            e.NewValues["EditorUserId"] = editor.UserID.ToString();
            e.NewValues["EditedDate"]   = DateTime.Now;
        }
        else
        {
            ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status));
            e.Cancel        = true;
        }
    }
コード例 #14
0
 partial void OnScientificNameSaved(ScientificName scientificName);
コード例 #15
0
 partial void OnScientificNameCreated(ScientificName scientificName);
コード例 #16
0
 public void DeleteScientificName(ScientificName scientific)
 {
     _db.ScientificNames.Remove(scientific);
     _db.SaveChanges();
 }
コード例 #17
0
 partial void OnScientificNameSaving(ScientificName scientificName);
コード例 #18
0
        public IActionResult NameDelete(ScientificName scientific)
        {
            _db.DeleteScientificName(scientific);

            return(RedirectToAction(nameof(GetScientificNames)));
        }
コード例 #19
0
 partial void OnScientificNameUpdated(ScientificName scientificName);
コード例 #20
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ScientificNames EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToScientificNames(ScientificName scientificName)
 {
     base.AddObject("ScientificNames", scientificName);
 }
コード例 #21
0
 partial void OnScientificNameDeleted(ScientificName scientificName);
コード例 #22
0
 public override int GetHashCode()
 {
     return(ScientificName.GetHashCode());
 }