private VMs.User ConvertVMUser(Data.User user) { VMs.User result = new VMs.User(); try { result.Id = user.Id; result.Name = user.Name; result.Type = user.Type.ToString(); result.Login = user.Login; result.Password = user.Password; result.Company = user.Company; return(result); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult <bool> > Save([FromBody] VMs.User user) { try { //Validation if (!context.Users .Where(x => x.RowStatus == Base.enRowStatus.Active && x.Login == user.Login && x.Email == user.Email) .Any()) { // USERS var userId = context.Users .Max(x => x.Id); var dataUser = new Data.User { Id = ++userId, Company = user.Company, Login = user.Login, Name = user.Name, Password = user.Password, Email = user.Email, TypeInner = (short)Enum.Parse(typeof(enUserType), user.Type), RowStatus = Base.enRowStatus.Active, RowDate = DateTime.Now, }; context.Users.Add(dataUser); await context.SaveChangesAsync(); return(OkResponse(true)); } else { throw new Exception("Usuário já cadastrado!"); } } catch (Exception ex) { return(BadRequestResponse(ex)); } finally { context.Dispose(); } }
public VMs.User ConvertVMUser(Data.User user) { try { VMs.User result = new VMs.User { Id = user.Id, Name = user.Name, Company = user.Company, Login = user.Login, Password = user.Password, Email = user.Email, Type = user.Type.ToString() }; return(result); } catch (Exception ex) { throw ex; } }