Exemple #1
0
        public Guardian Post(Guardian guardian)
        {
            var item = guardian.GetDataObject();

            using (var dbContext = new SMSEntities())
            {
                if (item.Id == 0)
                {
                    if (!IsAlreadyExist(item.Name))
                    {
                        dbContext.guardians.Add(item);
                        dbContext.SaveChanges();
                    }
                }
                else
                {
                    dbContext.Entry(item).State = EntityState.Modified;
                    dbContext.SaveChanges();
                }
            }
            guardian.Id = item.Id;
            return(guardian);
        }