Example #1
0
 public TipService(UnitofWork uow)
 {
     _uow = uow;
     _tiplerRepository       = _uow.GetRepository <tipler>();
     _kisilerRepository      = _uow.GetRepository <kisiler>();
     _hesapHareketRepository = _uow.GetRepository <hesap_hareket>();
     _tipDTO = new ETiplerDTO();
 }
        public ActionResult TipGuncelle(ETiplerDTO model)
        {
            bool durum = _tipService.TipGuncelle(model);

            if (durum == true)
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }

            else
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
        }
Example #3
0
        public bool TipGuncelle(ETiplerDTO model)
        {
            List <hesap_hareket> aidatBorclandirmasi = new List <hesap_hareket>();

            using (var context = new MyArchContext())
            {
                aidatBorclandirmasi = context.Database.SqlQuery <hesap_hareket>("SELECT * FROM hesap_hareket LEFT JOIN bagimsiz_bolumler ON hesap_hareket.bagimsiz_id = bagimsiz_bolumler.id WHERE bagimsiz_bolumler.tip ='" + model.bagimsiz_tip + "' and hesap_hareket.yil = '" + DateTime.Now.Year + "' and hesap_hareket.para_birimi = 'TL' ").ToList();
            }

            try
            {
                foreach (var item in aidatBorclandirmasi)
                {
                    kisiler kisi = new kisiler();
                    using (var context = new MyArchContext())
                    {
                        kisiler kisiIdModel = _kisilerRepository.Find(item.kisi_id);

                        //hesap hareket aidat borçlandırması güncelleme işlemi
                        int hhGuncelle = context.Database.ExecuteSqlCommand("update hesap_hareket set borc='" + model.aidat_tutar + "',bakiye='" + model.aidat_tutar + "' where id = '" + item.id + "'");

                        //kisi güncelle
                        if (item.para_birimi == "TL")
                        {
                            var borc = (from u in _hesapHareketRepository.GetAll().Where(x => x.para_birimi == "TL")
                                        where u.kisi_id == item.kisi_id
                                        select new EKisiDTO
                            {
                                borc_tl = u.borc,
                            }).ToList();

                            double toplamAlacak = borc.AsEnumerable().Sum(o => o.borc_tl);
                            kisiIdModel.borc_tl = toplamAlacak;

                            _kisilerRepository.Update(kisiIdModel);
                            _uow.SaveChanges();
                        }
                        if (item.para_birimi == "USD")
                        {
                            var borc = (from u in _hesapHareketRepository.GetAll().Where(x => x.para_birimi == "USD")
                                        where u.kisi_id == item.kisi_id
                                        select new EKisiDTO
                            {
                                borc_dolar = u.borc,
                            }).ToList();

                            double toplamAlacak = borc.AsEnumerable().Sum(o => o.borc_dolar);
                            kisiIdModel.borc_dolar = toplamAlacak;

                            _kisilerRepository.Update(kisiIdModel);
                            _uow.SaveChanges();
                        }
                        //euro yapılacak
                        //if (item.para_birimi == "USD")
                        //{
                        //    var borc = (from u in _hesapHareketRepository.GetAll()
                        //                where u.kisi_id == item.kisi_id
                        //                select new EKisiDTO
                        //                {
                        //                    borc_dolar = u.borc,
                        //                }).ToList();

                        //    double toplamAlacak = borc.AsEnumerable().Sum(o => o.borc_dolar);
                        //    kisiIdModel.borc_dolar = toplamAlacak;
                        //}
                    }
                }

                using (var context = new MyArchContext())
                {
                    int tipGuncelle = context.Database.ExecuteSqlCommand("update tipler set aidat_tutar='" + model.aidat_tutar + "' where id = '" + model.id + "'");

                    int bbAidatGuncelle = context.Database.ExecuteSqlCommand("update bagimsiz_bolumler set aidat_tutari='" + model.aidat_tutar + "' where tip_id = '" + model.id + "'");

                    if (tipGuncelle > 0 && bbAidatGuncelle > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }