Esempio n. 1
0
        public bool UpdateSifarnik(ESifarnik tipSifarnika, UpdateSifarnikRequestModel model)
        {
            model.Scope = this.inputParameters.Scope;
            var update = inputParameters.UpdateSifarnikService.GetUpdateSifarnici();

            return(update[tipSifarnika].Invoke(context, model, Scope));
        }
Esempio n. 2
0
 public IActionResult UpdateSifarnik(ESifarnik tipSifarnika, int id, [FromBody] UpdateSifarnikRequestModel model)
 {
     model.Id = id;
     if (sifarnikService.UpdateSifarnik(tipSifarnika, model))
     {
         logService.Akcija(Core.Constants.LogLevel.Info,
                           Core.Constants.LogKategorija.sifarnici,
                           Core.Constants.LogAkcija.sifarnik_izmijeni_red,
                           "ESifarnik: " + tipSifarnika,
                           authService.TrenutniKorisnik().KorisnickoIme
                           );
         return(Ok());
     }
     return(BadRequest());
 }
Esempio n. 3
0
        public bool UpdateEntity <TEntity>(Context context, UpdateSifarnikRequestModel model, TEntity entity, DbSet <TEntity> entities, ILifetimeScope scope) where TEntity : class
        {
            var securityLevel = new SecurityLevel {
                Update = true
            };

            try
            {
                foreach (KeyValuePair <string, object> polje in model.Sifarnik)
                {
                    try
                    {
                        if (polje.Key.ToLower() == "isdeleted")
                        {
                            entities.Remove(entity);
                        }
                        else
                        {
                            var info = entity.GetType().GetProperty(ToUpperFirstLetter(polje.Key));
                            if (info != null)
                            {
                                Type t = Nullable.GetUnderlyingType(info.PropertyType) ?? info.PropertyType;

                                if (t.GetTypeInfo().IsEnum)
                                {
                                    info.SetValue(entity, Convert.ChangeType(Enum.Parse(t, polje.Value.ToString()), t));
                                }
                                else
                                {
                                    JsonElement json        = (JsonElement)polje.Value;
                                    var         valueString = json.ToString();
                                    var         value       = Convert.ChangeType(valueString, t);
                                    info.SetValue(entity, value);
                                    //info.SetValue(entity, Convert.ChangeType(polje.Value, t));
                                }
                            }
                        }
                    }
                    catch (Exception) { }
                }
                context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }