Пример #1
0
        /// <summary>
        /// The create project.
        /// </summary>
        /// <param name="project">
        /// The project.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int CreateProject(NewProject project)
        {
            // returns null if ok, 1 if fails, 2 if the project with similar name already exists
            try
            {
                project.ParsedStartDate = DateTime.Parse(project.StartDate);
                project.ParsedEstFinishDate = DateTime.Parse(project.EstFinishDate);
                var createcontext =
                    new ScrumNotesDbClassDataContext(
                        ConfigurationManager.ConnectionStrings["ScrumNotesCombinerConnectionString"].ToString());
                int? id = createcontext.Projects.Count() + 1;
                IQueryable<Project> projects = from p in createcontext.Projects
                                               where p.Allias.Equals(project.Title)
                                               select p;
                if (projects.Count() != 0)
                {
                    createcontext.Dispose();
                    return 2;
                }

                int newid = createcontext.Projects.Count() + 1;
                var record = new Project
                                 {
                                     Allias = project.Title,
                                     Comments = project.Comments,
                                     EstFinishDate = project.ParsedEstFinishDate,
                                     Id = newid,
                                     ProjectAdminId = project.Admin,
                                     StartDate = project.ParsedStartDate
                                 };
                createcontext.Projects.InsertOnSubmit(record);
                createcontext.Projects.Context.SubmitChanges();
                createcontext.Dispose();
                return 0;
            }
            catch (Exception e)
            {
                return 1;
            }
        }
 partial void UpdateProject(Project instance);
 partial void DeleteProject(Project instance);
 partial void InsertProject(Project instance);