public async Task <IActionResult> PutSecurityRoleAction([FromRoute] int id, [FromBody] SecurityRoleAction securityRoleAction) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != securityRoleAction.Id) { return(BadRequest()); } _context.Entry(securityRoleAction).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SecurityRoleActionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([FromBody] CreateViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SalesState modelo = new SalesState { Description = model.Description, CompanyId = model.CompanyId, Enabled = true }; _context.SalesStates.Add(modelo); try { await _context.SaveChangesAsync(); } catch { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Create([FromBody] CreateSystemScreenViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SystemScreen systemScreen = new SystemScreen { Description = model.Description, Enabled = model.Enabled, Entity = model.Entity, Icon = model.Icon, IsDefault = model.IsDefault, Orden = model.Orden, ParentId = model.ParentId, Path = model.Path }; _context.SystemScreen.Add(systemScreen); try { await _context.SaveChangesAsync(); } catch { return(BadRequest()); } return(Ok(systemScreen.Id)); }
public async Task <IActionResult> Create([FromBody] CreateExchangeCurrencyViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ExchangeCurrency modelo = new ExchangeCurrency { Description = model.Description, CompanyId = model.CompanyId, Quote = model.Quote, Enabled = true }; _context.ExchangeCurrencies.Add(modelo); try { await _context.SaveChangesAsync(); } catch { return(BadRequest()); } return(Ok()); }
public async Task<IActionResult> PutTrackerLog([FromRoute] Int64 id, [FromBody] TrackerLog trackerLog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != trackerLog.Id) { return BadRequest(); } _context.Entry(trackerLog).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrackerLogExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task <IActionResult> Create([FromBody] CreateCascadeViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } City modelo = new City { Description = model.Description, Enabled = true, StateId = model.ParentId, }; _context.Cities.Add(modelo); try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest()); } return(Ok()); }
public async Task<IActionResult> PutConfigScreen([FromRoute] int id, [FromBody] ConfigScreen configScreen) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != configScreen.Id) { return BadRequest(); } _context.Entry(configScreen).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConfigScreenExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task <IActionResult> Create([FromBody] CreateDependentViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } State modelo = new State { Description = model.Description, Enabled = true, CountryId = model.ParentId }; _context.States.Add(modelo); try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Create([FromBody] CreateCustomerViewModel model) { string strRuta = _config["CustomerAvatar"]; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Customer modelo = new Customer { CompanyId = model.CompanyId, Enabled = true, Address = model.Address, CountryId = model.CountryId, StateId = model.StateId, CityId = model.CityId, Names = model.Names, Phone = model.Phone, DateInitial = DateTime.Now, Documento = model.Documento, DocumentTypeId = model.DocumentTypeId, Email = model.Email, Favorite = model.Favorite, Observation = model.Observation, PriceListId = model.PriceListId }; _context.Customers.Add(modelo); try { await _context.SaveChangesAsync(); //Guardo el avatar if (modelo.Id > 0) { if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo))) { strRuta = strRuta + "//" + modelo.Id.ToString() + "//" + model.LogoName; System.IO.FileInfo file = new System.IO.FileInfo(strRuta); file.Directory.Create(); System.IO.File.WriteAllBytes(strRuta, Convert.FromBase64String(model.Logo.Substring(model.Logo.LastIndexOf(',') + 1))); modelo.Logo = strRuta; } } _context.Entry(modelo).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public async Task <IActionResult> CreateShop(Shop shop) { if (ModelState.IsValid) { await dbContext.Shops.AddAsync(shop); var result = await dbContext.SaveChangesAsync(); if (result > 0) { return(RedirectToAction("SeeAllShops")); } } return(View()); }
public async Task <IActionResult> Create([FromBody] CreateGeoTrackerViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } GeoTracker geoTracker = new GeoTracker { Enabled = true, GpsModel = model.GpsModel, Identifier = model.Identifier, CreationDate = DateTime.Now }; _context.GeoTrackers.Add(geoTracker); try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest()); } return(Ok()); }
public async Task <ActionResult> Index_post(IFormCollection Listqustion) { List <Quiz> QustionList = _adb.QuizQUS.ToList(); int count = 0; foreach (Quiz Qustion in QustionList) { ViewData["Answer" + Qustion.id] = Listqustion["" + Qustion.id]; await _adb.SaveChangesAsync(); String s = Listqustion["" + Qustion.id]; if (Qustion.answer.Trim().Equals(s.Trim())) { ViewData["Correct Answer " + Qustion.id] = "true"; count++; } else { ViewData["Correct Answer " + Qustion.id] = Qustion.answer; } } ViewData["mark"] = count; ViewData["form"] = QustionList.Count; ViewBag.Qustion = _adb.QuizQUS.ToList(); return(View()); }
public async Task <IActionResult> Create([FromBody] CreateGeoreferenceViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Georeference georeference = new Georeference { Identifier = model.Identifier, CreationDate = DateTime.Now, Enabled = true, GeoTrackerId = model.GeoTrackerId, Latitude = model.Latitude, Longitude = model.Longitude, TrackerLogId = model.TrackerLogId }; _context.Georeferences.Add(georeference); try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest()); } return(Ok()); }
public async Task <ActionResult> Crear([FromBody] CreateUserViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var email = model.Email.ToLower(); if (await _context.SecurityUsers.AnyAsync(x => x.Email == email)) { return(BadRequest("El email ya existe")); } CrearPasswordHash(model.Password, out byte[] passwordHash, out byte[] passwordSalt); SecurityUser usuario = new SecurityUser { SecurityRoleId = model.SecurityRoleId, Nombre = model.Nombre, Tipo_documento = model.Tipo_documento, Num_documento = model.Num_documento, Direccion = model.Direccion, Telefono = model.Telefono, Email = model.Email.ToLower(), Password_hash = passwordHash, Password_salt = passwordSalt, Condicion = true }; _context.SecurityUsers.Add(usuario); try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Update([FromBody] List <UpdateSystemRoleScreenViewModel> listmodel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <SystemRoleScreen> listsystemRoleScreens = _context.SystemRoleScreen.ToList(); List <SystemRoleScreen> listBorrar = new List <SystemRoleScreen>(); List <SystemRoleScreen> listGrabar = new List <SystemRoleScreen>(); try { foreach (var item in listmodel) { SystemRoleScreen systemRoleScreen = listsystemRoleScreens.Where(x => x.SystemRoleId == item.SystemRoleId && x.SystemScreenId == item.SystemScreenId).FirstOrDefault(); //Si viene desabilitado, me fijo que no este dado de alta if (!item.Enabled) { if (systemRoleScreen != null) { listBorrar.Add(systemRoleScreen); } //Sino no esta no hago nada } else { if (systemRoleScreen == null) { //Si no esta lo doy de alta systemRoleScreen = new SystemRoleScreen(); systemRoleScreen.SystemRoleId = item.SystemRoleId; systemRoleScreen.SystemScreenId = item.SystemScreenId; listGrabar.Add(systemRoleScreen); } } } //Agrego _context.SystemRoleScreen.AddRange(listGrabar); //Borro _context.SystemRoleScreen.RemoveRange(listBorrar); await _context.SaveChangesAsync(); } catch { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Create([FromBody] CreationLogErrorViewModel model) { try { LogError log = new LogError { CompanyId = model.CompanyId, CreationDate = DateTime.Now, Path = model.Path, SecurityUserId = model.SecurityUserId, Error = StringExt.Truncate(model.Error, 7999) }; _context.LogErrors.Add(log); await _context.SaveChangesAsync(); return(Ok(log.Id)); } catch { return(BadRequest()); } }
public async Task <IActionResult> Update([FromBody] List <UpdateSystemScreenFieldViewModel> listmodel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <SystemScreenField> screensUpdate = new List <SystemScreenField>(); List <SystemScreenField> screensAdd = new List <SystemScreenField>(); List <SystemScreenField> screensRemove = new List <SystemScreenField>(); //Actualiza masivamente foreach (var item in listmodel) { if (item.Id == null && item.IsNew == true) { SystemScreenField systemScreen = new SystemScreenField { DefaultValue = item.DefaultValue, Orden = item.Orden, Enabled = item.Enabled, FieldName = item.FieldName, Name = item.Name, Required = item.Required, SystemScreenId = item.SystemScreenId, Visible = item.Visible }; screensAdd.Add(systemScreen); } else { //Si no es a borrar, el modelo SystemScreenField systemScreen = _context.SystemScreenField.Find(item.Id); //Ahora me fijo si lo elimino o lo actualizo if (item.IsRemoved) { screensRemove.Add(systemScreen); } else { systemScreen.DefaultValue = item.DefaultValue; systemScreen.Orden = item.Orden; systemScreen.Enabled = item.Enabled; systemScreen.FieldName = item.FieldName; systemScreen.Name = item.Name; systemScreen.Required = item.Required; systemScreen.SystemScreenId = item.SystemScreenId; systemScreen.Visible = item.Visible; screensUpdate.Add(systemScreen); } } } //Agrego _context.SystemScreenField.AddRange(screensAdd); //Actualizo _context.SystemScreenField.UpdateRange(screensUpdate); //Borro _context.SystemScreenField.RemoveRange(screensRemove); try { await _context.SaveChangesAsync(); } catch { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Update([FromBody] List <UpdateSystemActionViewModel> listmodel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <SystemAction> screensUpdate = new List <SystemAction>(); List <SystemAction> screensAdd = new List <SystemAction>(); List <SystemAction> screensRemove = new List <SystemAction>(); //Actualiza masivamente foreach (var item in listmodel) { if (item.Id == null && item.IsNew == true) { SystemAction systemScreen = new SystemAction { Enabled = item.Enabled, SystemScreenId = item.SystemScreenId, Code = item.Code, Description = item.Description }; screensAdd.Add(systemScreen); } else { //Si no es a borrar, el modelo SystemAction systemScreen = _context.SystemAction.Find(item.Id); //Ahora me fijo si lo elimino o lo actualizo if (item.IsRemoved) { screensRemove.Add(systemScreen); } else { systemScreen.Enabled = item.Enabled; systemScreen.Code = item.Code; systemScreen.Description = item.Description; systemScreen.SystemScreenId = item.SystemScreenId; screensUpdate.Add(systemScreen); } } } //Agrego _context.SystemAction.AddRange(screensAdd); //Actualizo _context.SystemAction.UpdateRange(screensUpdate); //Borro _context.SystemAction.RemoveRange(screensRemove); try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Create([FromBody] CreateProductViewModel model) { string strRuta = _config["ProductAvatar"]; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!string.IsNullOrEmpty(model.Codigo)) { //Verifico si el codigo existe if (_context.Products.Where(x => x.Codigo == model.Codigo.ToUpper().Trim()).Any()) { return(BadRequest(new { Message = "Código repetido" })); } } Product modelo = new Product { Awaiting = model.Awaiting ?? false, BrandId = model.BrandId, CategoryId = model.CategoryId, Codigo = model.Codigo?.ToUpper().Trim(), CompanyId = model.CompanyId, Cost = model.Cost, DateInitial = DateTime.Now, Description = model.Description, Discount = model.Discount ?? 0, Enabled = true, ExchangeCurrencyId = model.ExchangeCurrencyId, Gain = model.Gain, InStock = model.InStock ?? false, LocationId = model.LocationId, Name = model.Name?.Trim(), NameShort = model.NameShort?.Trim(), OutOfStock = model.OutOfStock ?? false, Price = model.Price ?? 0, Stock = model.Stock, StockMin = model.StockMin, SubCategoryId = model.SubCategoryId, CheckStock = model.CheckStock ?? false, ProductProviders = new List <ProductProviders>(), ProductPriceLists = new List <ProductPriceLists>() }; foreach (var prov in model.Providers) { ProductProviders productProviders = new ProductProviders { ProviderId = prov, ProductId = modelo.Id }; modelo.ProductProviders.Add(productProviders); } foreach (var price in model.ProductPriceLists) { ProductPriceLists productPriceLists = new ProductPriceLists { PriceListId = price.PriceList, ProductId = modelo.Id, Price = price.Price }; modelo.ProductPriceLists.Add(productPriceLists); } _context.Products.Add(modelo); try { await _context.SaveChangesAsync(); if (modelo.Id > 0) { //Codigo if (string.IsNullOrEmpty(modelo.Codigo)) { modelo.Codigo = modelo.Id.ToString(); } //Guardo el avatar if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo))) { strRuta = strRuta + "//" + modelo.Id.ToString() + "//" + model.LogoName; System.IO.FileInfo file = new System.IO.FileInfo(strRuta); file.Directory.Create(); System.IO.File.WriteAllBytes(strRuta, Convert.FromBase64String(model.Logo.Substring(model.Logo.LastIndexOf(',') + 1))); modelo.Logo = strRuta; } } _context.Entry(modelo).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public async Task <IActionResult> Create([FromBody] CreateCompanyViewModel model) { string userPassword = CreatePassword(6); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string strRuta = _config["AvatarFiles"]; Company company = new Company { Name = model.Name, ContactName = model.ContactName, ContactLastName = model.ContactLastName, InitialDate = model.InitialDate, Email = model.Email, Phone = model.Phone, Website = model.Website, Address = model.Address, Postal = model.Postal, City = model.City, State = model.State, Country = model.Country, Schedule = model.Schedule, Comment = model.Comment, CreationDate = DateTime.Now, Enabled = true }; //Agrego los sectores if (model.CompanySectors != null) { company.CompanySectors = new List <CompanySector>(); foreach (var sector in model.CompanySectors) { CompanySector companySector = new CompanySector { CompanyId = company.Id, SectorId = sector.SectorId }; company.CompanySectors.Add(companySector); } } //Agrego las pantallas if (model.ConfigScreens != null) { company.ConfigScreen = new List <ConfigScreen>(); foreach (var item in model.ConfigScreens) { ConfigScreen configScreen = new ConfigScreen { CompanyId = company.Id, Description = item.Description, Enabled = item.Enabled, Orden = item.Orden, Icon = item.Icon, SystemScreenId = item.SystemScreenId }; //Dentro de las pantallas agrego los Atributos if (item.ConfigScreenFields != null) { configScreen.ConfigScreenFields = new List <ConfigScreenField>(); foreach (var field in item.ConfigScreenFields) { ConfigScreenField configScreenField = new ConfigScreenField { ConfigScreenId = item.Id, Name = field.Name, Required = field.Required, Visible = field.Visible, DefaultValue = field.DefaultValue, Orden = field.Orden, Enabled = field.Enabled, FieldName = field.FieldName, SystemScreenFieldId = field.SystemScreenFieldId, }; configScreen.ConfigScreenFields.Add(configScreenField); } } //Dentro de las pantallas agrego las Acciones if (item.SecurityActions != null) { configScreen.SecurityActions = new List <SecurityAction>(); foreach (var action in item.SecurityActions) { SecurityAction securityAction = new SecurityAction { ConfigScreenId = item.Id, Description = action.Description, Enabled = action.Enabled, SystemActionId = action.SystemActionId, }; configScreen.SecurityActions.Add(securityAction); } } company.ConfigScreen.Add(configScreen); } } _context.Companies.Add(company); await _context.SaveChangesAsync(); //Agrego los roles ////Agrego las pantallas que aplican para ese rol company.SecurityRoles = new List <SecurityRole>(); foreach (var rol in model.SecurityRoles) { int i = 0; SecurityRole securityRole = new SecurityRole { Name = rol.Name, CompanyId = company.Id, Description = rol.Description, Enabled = true, SystemRoleId = rol.SystemRoleId }; if (i == 0) { //Genero el usuario securityRole.Usuarios = new List <SecurityUser>(); CrearPasswordHash(userPassword, out byte[] passwordHash, out byte[] passwordSalt); SecurityUser user = new SecurityUser { CompanyId = company.Id, Condicion = true, Direccion = company.Address, Email = company.Email, Nombre = company.Name, SecurityRoleId = securityRole.Id, Password_hash = passwordHash, Password_salt = passwordSalt }; securityRole.Usuarios.Add(user); } i++; securityRole.SecurityRoleScreens = new List <SecurityRoleScreen>(); securityRole.SecurityRoleActions = new List <SecurityRoleAction>(); foreach (var screen in company.ConfigScreen) { //Si la pantalla esta en el rol, la agrego if (rol.SecurityRoleScreens.Where(x => x.SystemScreenId == screen.SystemScreenId).Any()) { SecurityRoleScreen securityRoleScreen = new SecurityRoleScreen { ConfigScreenId = screen.Id, SecurityRoleId = securityRole.Id }; securityRole.SecurityRoleScreens.Add(securityRoleScreen); foreach (var action in screen.SecurityActions) { if (rol.SecurityRoleActions.Where(x => x.SystemActionId == action.SystemActionId).Any()) { SecurityRoleAction securityRoleAction = new SecurityRoleAction { SecurityActionId = action.Id, SecurityRoleId = securityRole.Id }; securityRole.SecurityRoleActions.Add(securityRoleAction); } } } } company.SecurityRoles.Add(securityRole); } //Guardo el avatar if (company.Id > 0) { if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo))) { strRuta = strRuta + "//" + company.Id.ToString() + "//" + model.LogoName; System.IO.FileInfo file = new System.IO.FileInfo(strRuta); file.Directory.Create(); System.IO.File.WriteAllBytes(strRuta, Convert.FromBase64String(model.Logo.Substring(model.Logo.LastIndexOf(',') + 1))); company.Logo = strRuta; } } _context.Entry(company).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest()); } return(Ok(userPassword)); }