/// <summary> /// creates user data /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <GuidResult> CreateGuid(CredentialModel model) { var result = new GuidResult { ValidationResults = model.Validate() }; if (result.ValidationResults.Count == 0) { var randomGuid = new Guid(); if (string.IsNullOrEmpty(model.UserId)) { randomGuid = Guid.NewGuid(); model.UserId = randomGuid.ToString(); model.Expire = string.IsNullOrEmpty(model.Expire) ? "2629743" : model.Expire; } var entity = model.MapToEntity(); await _userCredRepository.Add(entity); result.CredentialModel = entity.MapToModel(); return(result); } return(result); }
/// <summary> /// updates user data /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <GuidResult> Update(CredentialModel model) { var result = new GuidResult { ValidationResults = model.Validate() }; if (result.ValidationResults.Count == 0) { var entity = await _userCredRepository.GetById(new Guid(model.UserId)); result.CredentialModel = entity.MapToModel(); if (entity != null) { entity.Username = string.IsNullOrEmpty(model.Username) ? entity.Username : model.Username; entity.Expire = string.IsNullOrEmpty(model.Expire) ? entity.Expire : model.Expire; entity.UserId = new Guid(model.UserId); await _userCredRepository.AddOrUpdate(entity); } result.CredentialModel = entity.MapToModel(); return(result); } return(result); }