Exemple #1
0
        public ActionResult SaveArtikl(ArtiklEntity artikl)
        {
            bool isSaved = false;

            DataAccessAdapterBase adapter = Helper.GetDataAccessAdapter(User.Identity.Name);

            using (adapter)
            {
                adapter.StartTransaction(System.Data.IsolationLevel.Serializable, "SaveArtikl");

                ArtiklEntity artikl4Save;

                if (artikl.ArtiklId == 0)
                {
                    artikl4Save          = artikl;
                    artikl4Save.IsActive = true;
                    artikl4Save.FirmaId  = UserEntity.GetFirmaId(adapter, User.Identity.Name);
                }
                else
                {
                    artikl4Save = ArtiklEntity.FetchArtikl(adapter, null, artikl.ArtiklId);
                    artikl4Save.UpdateDataFromOtherObject(artikl, null, null);
                }

                isSaved = adapter.SaveEntity(artikl4Save);

                adapter.Commit();
            }

            dynamic response = new { IsSaved = isSaved };

            return(CreateJsonResponse(response));
        }
Exemple #2
0
        public ActionResult SaveConfig(ConfigEntity config)
        {
            bool isSaved = false;

            if (config.AktivnaGodina >= 2005 && config.AktivnaGodina <= 2025)
            {
                DataAccessAdapterBase adapter = Helper.GetDataAccessAdapter(User.Identity.Name);
                using (adapter)
                {
                    adapter.StartTransaction(System.Data.IsolationLevel.Serializable, "SaveConfig");

                    ConfigEntity config4Save;
                    if (config.ConfigId == 0)
                    {
                        config4Save         = config;
                        config4Save.FirmaId = UserEntity.GetFirmaId(adapter, User.Identity.Name);
                    }
                    else
                    {
                        config4Save = ConfigEntity.FetchConfig(adapter, null, config.ConfigId);
                        config4Save.UpdateDataFromOtherObject(config, null, null);
                    }

                    isSaved = adapter.SaveEntity(config4Save);

                    adapter.Commit();
                }
            }

            dynamic response = new { IsSaved = isSaved };

            return(CreateJsonResponse(response));
        }
Exemple #3
0
        public ActionResult SaveTarifa(TarifaEntity tarifa)
        {
            bool isSaved = false;

            DataAccessAdapterBase adapter = Helper.GetDataAccessAdapter(User.Identity.Name);

            using (adapter)
            {
                adapter.StartTransaction(System.Data.IsolationLevel.Serializable, "SaveTarifa");

                TarifaEntity tarifa4Save;

                if (tarifa.TarifaId == 0)
                {
                    tarifa.IsActive     = true;
                    tarifa4Save         = tarifa;
                    tarifa4Save.FirmaId = UserEntity.GetFirmaId(adapter, User.Identity.Name);
                }
                else
                {
                    tarifa4Save = TarifaEntity.FetchTarifa(adapter, null, tarifa.TarifaId);
                    tarifa4Save.UpdateDataFromOtherObject(tarifa, null, null);
                }

                isSaved = adapter.SaveEntity(tarifa4Save);

                adapter.Commit();
            }

            dynamic response = new { IsSaved = isSaved };

            return(CreateJsonResponse(response));
        }
Exemple #4
0
        public ActionResult SavePdv(PdvEntity pdv)
        {
            bool isSaved = false;

            DataAccessAdapterBase adapter = Helper.GetDataAccessAdapter(User.Identity.Name);

            using (adapter)
            {
                adapter.StartTransaction(System.Data.IsolationLevel.Serializable, "SavePdv");

                PdvEntity pdv4Save;

                if (pdv.PdvId == 0)
                {
                    pdv4Save         = pdv;
                    pdv4Save.FirmaId = UserEntity.GetFirmaId(adapter, User.Identity.Name);
                }
                else
                {
                    pdv4Save = PdvEntity.FetchPdv(adapter, null, pdv.PdvId);
                    pdv4Save.UpdateDataFromOtherObject(pdv, null, null);
                }

                isSaved = adapter.SaveEntity(pdv4Save);

                adapter.Commit();
            }

            dynamic response = new { IsSaved = isSaved };

            return(CreateJsonResponse(response));
        }
Exemple #5
0
        public ActionResult SaveRacun(string racunGlavaJson, string racunStavkaCollectionJson)
        {
            DataAccessAdapterBase adapter = Helper.GetDataAccessAdapter(User.Identity.Name);
            RacunGlavaEntity      racunGlava4Save;
            bool isSaved = false;

            using (adapter)
            {
                adapter.StartTransaction(System.Data.IsolationLevel.Serializable, "SaveRacun");

                JsonSerializerSettings jsonSettings   = new JsonSerializerSettings();
                CultureInfo            currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
                jsonSettings.Culture = currentCulture;

                RacunGlavaEntity racunGlava = JsonConvert.DeserializeObject <RacunGlavaEntity>(racunGlavaJson, jsonSettings);

                if (racunGlava.RacunGlavaId == 0)
                {
                    long firmaId = UserEntity.GetFirmaId(adapter, User.Identity.Name);

                    racunGlava4Save            = racunGlava;
                    racunGlava4Save.Godina     = ConfigEntity.GetInstance(adapter, firmaId).AktivnaGodina;
                    racunGlava4Save.BrojRacuna = BrojacEntity.GetNextNumber(adapter, firmaId, BrojacEnum.Racun, racunGlava4Save.Godina);
                    racunGlava4Save.FirmaId    = firmaId;
                }
                else
                {
                    PrefetchPath2 prefetchPath = new PrefetchPath2(EntityType.RacunGlavaEntity);
                    prefetchPath.Add(RacunGlavaEntity.PrefetchPathRacunStavkaCollection);

                    racunGlava4Save = RacunGlavaEntity.FetchRacunGlava(adapter, prefetchPath, racunGlava.RacunGlavaId);
                    racunGlava4Save.UpdateDataFromOtherObject(racunGlava, null, null);
                }

                racunGlava4Save.TarifaStopa = TarifaEntity.FetchTarifa(adapter, null, racunGlava4Save.TarifaId).Stopa;

                if (racunGlava4Save.Godina != racunGlava4Save.Datum.Year)
                {
                    // TODO: create mechanism for pushing errors to client. Currently check is on client. Remove client check after push error mechanism is implemented.
                }
                else
                {
                    isSaved = adapter.SaveEntity(racunGlava4Save, true, false);
                }

                if (isSaved)
                {
                    IEnumerable <RacunStavkaEntity> racunStavkaCollectionToDelete =
                        racunGlava4Save.RacunStavkaCollection.GetEntitiesNotIncludedInJson(racunStavkaCollectionJson, jsonSettings);

                    foreach (RacunStavkaEntity racunStavka in racunStavkaCollectionToDelete)
                    {
                        if (isSaved)
                        {
                            racunGlava4Save.RacunStavkaCollection.Remove(racunStavka);
                            isSaved = adapter.DeleteEntity(racunStavka);
                        }
                    }

                    racunGlava4Save.RacunStavkaCollection.UpdateEntityCollectionFromJson(racunStavkaCollectionJson, RacunStavkaFields.RacunStavkaId, null, null, jsonSettings);
                    foreach (RacunStavkaEntity racunStavka in racunGlava4Save.RacunStavkaCollection)
                    {
                        if (isSaved)
                        {
                            racunStavka.RecalculateData(racunGlava.TarifaStopa);
                            isSaved = adapter.SaveEntity(racunStavka, false, false);
                        }
                    }
                }

                adapter.Commit();
            }

            dynamic response = new
            {
                IsSaved      = isSaved,
                RacunGlavaId = racunGlava4Save.RacunGlavaId
            };

            return(CreateJsonResponse(response));
        }