public HttpResponseMessage AddUserToGroup([FromBody] User_Groups Model) { bool SuccessfullSave = User_GroupsHelper.Save(Model); if (!SuccessfullSave) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } return(Request.CreateResponse(HttpStatusCode.Created)); }
public HttpResponseMessage SaveUserGroups([FromBody] User_Groups UserGroup) { bool SuccessfullSaved = UserGroupHelper.Save(UserGroup); if (!SuccessfullSaved) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } return(Request.CreateResponse(HttpStatusCode.Created)); }
public static async Task <User_Info> New(User_Info data, User_Groups group = null) { try { var birthdate = (data.birthday != null) ? Convert.ToDateTime(data.birthday) : DateTime.Now; var user = new User_Info() { username = data.username, password = Functions.Functions.Encode.StringToBase64(data.password), email = data.email, display_name = data.display_name ?? "User", birthday = (data.birthday != null) ? Convert.ToDateTime(data.birthday) : DateTime.Now, unique_id = Guid(data.username).ToString(), profile_created = DateTime.Now }; User_Groups groupDB; if (group != null) { groupDB = await db.User_Groups.Where(x => x.type == group.type).FirstAsync(); } else { groupDB = await db.User_Groups.Where(x => x.type == "user").FirstAsync(); } user.group = groupDB.Id; user.User_Groups = groupDB; db.User_Info.Add(user); await db.SaveChangesAsync(); await History.Create(History.Type.User, new History_User() { user_action = "User create -> " + user.unique_id, user_datetime = DateTime.Now, user_id = user.unique_id, user_movie = "", user_type = "UserCreationSuccess" }); return(user); } catch (Exception ex) { await History.Create(History.Type.API, new History_API() { api_action = "Exception caught on User.Create.New -> Message: " + ex.Message, api_type = "Exception" }); } return(null); }
public static USER_GROUPS ToTable(this User_Groups Model) { if (Model == null) { return(null); } return(new USER_GROUPS() { UserId = Model.UserId, GroupId = Model.GroupId }); }
/// <summary> /// Converts this instance of <see cref="USER_GROUPS"/> to an instance of <see cref="User_Groups"/>. /// </summary> /// <param name="entity"><see cref="USER_GROUPS"/> to convert.</param> public static User_Groups ToModel(this USER_GROUPS entity) { if (entity == null) { return(new User_Groups()); } var dto = new User_Groups(); dto.UserId = entity.UserId; dto.GroupId = entity.GroupId; entity.OnDTO(dto); return(dto); }
/// <summary> /// Converts this instance of <see cref="User_Groups"/> to an instance of <see cref="USER_GROUPS"/>. /// </summary> /// <param name="dto"><see cref="User_Groups"/> to convert.</param> public static USER_GROUPS ToTable(this User_Groups dto) { if (dto == null) { return(null); } var entity = new USER_GROUPS(); entity.UserId = dto.UserId; entity.GroupId = dto.GroupId; dto.OnEntity(entity); return(entity); }
/// <summary> /// Edit user data in database and save it /// </summary> /// <param name="user">User_Info</param> /// <returns>bool</returns> public static async Task <bool> Data(User_Info user, User_Groups group) { var u = await Get.ByGuid(user.unique_id); if (u != null && u.username == user.username) { if (group != null && u.User_Groups != group) { try { User_Info tmp = new User_Info() { birthday = u.birthday, display_name = u.display_name, email = u.email, last_logon = u.last_logon, password = u.password, profile_created = u.profile_created, profile_image = u.profile_image, unique_id = u.unique_id, username = u.username }; db.User_Info.Remove(u); //edit tmp user group tmp.group = group.Id; db.User_Info.Add(tmp); await db.SaveChangesAsync(); return(true); } catch (DbEntityValidationException ex) { await History.Create(History.Type.API, new History_API() { api_action = "Exception caught on User.Edit.Data -> " + ex.Message, api_type = "Exception -> User.Edit.Data", api_datetime = DateTime.Now }); return(false); } } } return(false); }
public static User_Groups GetGruposByPrimaryKey(int UserId, int GroupId) { User_Groups result = new User_Groups(); using (HelpDeskApfEntities context = new HelpDeskApfEntities()) { var queryResult = context.USER_GROUPS.SingleOrDefault(x => x.UserId == UserId && x.GroupId == GroupId); if (queryResult != null) { result = queryResult.ToModel(); } } return(result); }
public static bool Save(User_Groups model) { bool result; using (HelpDeskApfEntities context = new HelpDeskApfEntities()) { try { context.USER_GROUPS.Add(model.ToTable()); context.SaveChanges(); result = true; } catch (Exception) { result = false; } } return(result); }
/// <summary> /// Invoked when <see cref="ToTable"/> operation is about to return. /// </summary> /// <param name="entity"><see cref="USER_GROUPS"/> converted from <see cref="User_Groups"/>.</param> static partial void OnEntity(this User_Groups dto, USER_GROUPS entity);
/// <summary> /// Invoked when <see cref="ToModel"/> operation is about to return. /// </summary> /// <param name="dto"><see cref="User_Groups"/> converted from <see cref="USER_GROUPS"/>.</param> static partial void OnDTO(this USER_GROUPS entity, User_Groups dto);