Пример #1
0
        /// <summary>
        /// Edit an existing subject.
        /// </summary>
        /// <param name="model">Subject details to edit.</param>
        /// <returns>0 on subject already exists, 1 on success, 2 on unexpected database error.</returns>
        public int Edit(Subject model)
        {
            int            result   = 0;
            List <Subject> subjects = new List <Subject>();

            if (model != null)
            {
                subjects = Details(model.UserId);
            }

            try
            {
                using (TaskDatabase db = new TaskDatabase())
                {
                    Subject query = (from subject in subjects
                                     where subject.Name == model.Name && subject.Id != model.Id
                                     select subject).FirstOrDefault();

                    if (query == null)
                    {
                        result = db.Update(model);
                    }
                }
            }
            catch (Exception)
            {
                result = 2;
            }

            return(result);
        }
        /// <summary>
        /// Edit an existing grade.
        /// </summary>
        /// <param name="model">Grade details to edit.</param>
        /// <returns>0 on failure, 1 on success, 2 on unexpected database error.</returns>
        public int Edit(Grade model)
        {
            int result = 0;

            try
            {
                using (TaskDatabase db = new TaskDatabase())
                {
                    result = db.Update(model);
                }
            }
            catch (Exception)
            {
                result = 2;
            }

            return(result);
        }