示例#1
0
        public int Save(UserDTO dtoToSave)
        {
            User userToSave = DataConverter.Instance.GetEntity(dtoToSave) as User;

            //TODO: Ask if the Context is better to initialize with the DAO intialization, or create a new one each time
            using (AirsoftBaseContext context = new AirsoftBaseContext())
            {
                if (!context.Users.Where(u => u.Login == userToSave.Login).Any())
                {
                    context.Users.Add(userToSave);
                    context.SaveChanges();
                    return((int)SaveStatusCode.SaveOK);
                }
                else
                {
                    return((int)SaveStatusCode.NameAllreadyTaken);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Try to save a new Entity to Database and get operation result code
        /// </summary>
        /// <param name="dtoToSave">Object to save</param>
        /// <returns>Operation result code</returns>
        public int Save(TeamDTO dtoToSave)
        {
            Team teamToSave = DataConverter.Instance.GetEntity(dtoToSave) as Team;

            //TODO: Ask if the Context is better to initialize with the DAO intialization, or create a new one each time
            using (AirsoftBaseContext context = new AirsoftBaseContext())
            {
                if (!context.Teams.Where(t => t.Title == teamToSave.Title).Any())
                {
                    context.Teams.Add(teamToSave);
                    context.SaveChanges();
                    return((int)SaveStatusCode.SaveOK);
                }
                else
                {
                    return((int)SaveStatusCode.NameAllreadyTaken);
                }
            }
        }