예제 #1
0
        public string projeDuzenle(string url, int firma_id, HttpRequestBase Request)
        {
            try
            {
                vrlfgysdbEntities db = new vrlfgysdbEntities();

                proje_surec dbPrj = db.proje_surec.Where(e => e.url.Equals(url) && e.flag != durumlar.silindi).FirstOrDefault();

                if (dbPrj == null || url == null || url.Equals(""))
                {
                    return(yeniProje(firma_id, Request));
                }
                else if (!(dbPrj.flag != durumlar.silindi))
                {
                    return("");
                }

                string urlTemp = dbPrj.url;

                foreach (var property in dbPrj.GetType().GetProperties())
                {
                    try
                    {
                        var response = Request[property.Name];
                        if (response == null)
                        {
                            if (response == null)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            PropertyInfo propertyS = dbPrj.GetType().GetProperty(property.Name);
                            if (property.PropertyType == typeof(decimal))
                            {
                                propertyS.SetValue(dbPrj, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null);
                            }
                            else
                            {
                                propertyS.SetValue(dbPrj, Convert.ChangeType(response, property.PropertyType), null);
                            }
                        }
                    }
                    catch (Exception)
                    { }
                }

                dbPrj.url = urlTemp;

                string          isimControl   = "select * from proje_surec where id != " + dbPrj.id.ToString() + " and tur = " + ProjeSurecTur.proje + " and flag != " + durumlar.silindi.ToString() + " and isim = '" + dbPrj.isim + "' and firma_id = " + dbPrj.firma_id;
                ProjeSurecModel isimKontrolPs = db.Database.SqlQuery <ProjeSurecModel>(isimControl).FirstOrDefault();
                if (isimKontrolPs != null)
                {
                    return("proje_isim_hatasi");
                }

                bool kullaniciKontrol = firmaProjeKontrol(dbPrj.firma_id, dbPrj.id).Result;
                if (!kullaniciKontrol)
                {
                    return("proje_sayisi_hatasi");
                }

                db.Entry(dbPrj).State = EntityState.Modified;
                db.SaveChanges();

                /*#region proje_musteri
                 * int musteri_id = Convert.ToInt32(Request["musteri_id"].ToString());
                 * if (musteri_id != 0)
                 * {
                 *  proje_surec dbPs = db.proje_surec.Where(e => e.vid == dbPrj.vid).FirstOrDefault();
                 *  proje_musteri pm = db.proje_musteri.Where(e => e.flag == durumlar.aktif && e.proje_id == dbPs.id).FirstOrDefault();
                 *  if (pm == null)
                 *  {
                 *      pm = new proje_musteri();
                 *      pm.date = DateTime.Now;
                 *      pm.flag = durumlar.aktif;
                 *      pm.musteri_id = musteri_id;
                 *      pm.proje_id = dbPs.id;
                 *      int vidPm = 1;
                 *      if (db.proje_musteri.Count() != 0)
                 *      {
                 *          vidPm = db.proje_musteri.Max(e => e.vid) + 1;
                 *      }
                 *      int sortPm = 1;
                 *      if (db.proje_musteri.Count() != 0)
                 *      {
                 *          sortPm = db.proje_musteri.Max(e => e.sort) + 1;
                 *      }
                 *      pm.sort = sortPm;
                 *      pm.vid = vidPm;
                 *      db.proje_musteri.Add(pm);
                 *      db.SaveChanges();
                 *  }
                 *  else if (pm != null && pm.musteri_id != musteri_id)
                 *  {
                 *      pm.musteri_id = musteri_id;
                 *      db.Entry(pm).State = EntityState.Modified;
                 *      db.SaveChanges();
                 *  }
                 * }
                 * else if (musteri_id == 0)
                 * {
                 *  proje_surec dbPs = db.proje_surec.Where(e => e.vid == dbPrj.vid).FirstOrDefault();
                 *  proje_musteri pm = db.proje_musteri.Where(e => e.flag == durumlar.aktif && e.proje_id == dbPs.id).FirstOrDefault();
                 *  if (pm != null)
                 *  {
                 *      pm.flag = durumlar.silindi;
                 *      db.Entry(pm).State = EntityState.Modified;
                 *      db.SaveChanges();
                 *  }
                 * }
                 #endregion proje_musteri*/

                return(dbPrj.url);
            }
            catch (Exception e)
            {
                return("");
            }
        }
예제 #2
0
        public string yeniProje(int firma_id, HttpRequestBase Request)
        {
            try
            {
                vrlfgysdbEntities db = new vrlfgysdbEntities();

                int vid = 1;
                if (db.proje_surec.Count() != 0)
                {
                    vid = db.proje_surec.Max(e => e.vid) + 1;
                }
                int sort = 1;
                if (db.proje_surec.Count() != 0)
                {
                    sort = db.proje_surec.Max(e => e.sort) + 1;
                }

                proje_surec prj = new proje_surec();
                foreach (var property in prj.GetType().GetProperties())
                {
                    try
                    {
                        var response = Request[property.Name];
                        if (response == null && property.PropertyType != typeof(int))
                        {
                            if (response == null)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            PropertyInfo propertyS = prj.GetType().GetProperty(property.Name);
                            if (property.PropertyType == typeof(decimal))
                            {
                                propertyS.SetValue(prj, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null);
                            }
                            else if (property.PropertyType == typeof(int))
                            {
                                if (response == null)
                                {
                                    propertyS.SetValue(prj, Convert.ChangeType(0, property.PropertyType), null);
                                }
                                else
                                {
                                    propertyS.SetValue(prj, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null);
                                }
                            }
                            else
                            {
                                propertyS.SetValue(prj, Convert.ChangeType(response, property.PropertyType), null);
                            }
                        }
                    }
                    catch (Exception)
                    { }
                }

                string      strImageName = StringFormatter.OnlyEnglishChar(prj.isim);
                string      createdUrl   = strImageName;
                string      tempUrl      = createdUrl;
                bool        bulundu      = false;
                int         i            = 0;
                proje_surec pg           = new proje_surec();
                do
                {
                    pg = db.proje_surec.Where(e => e.url.Equals(tempUrl)).FirstOrDefault();
                    if (pg != null)
                    {
                        tempUrl = tempUrl + i.ToString();
                    }
                    else
                    {
                        createdUrl = tempUrl;
                        bulundu    = true;
                    }
                    i++;
                } while (!bulundu);
                prj.url      = createdUrl;
                prj.firma_id = firma_id;

                prj.flag    = durumlar.aktif;
                prj.date    = DateTime.Now;
                prj.vid     = vid;
                prj.ekleyen = GetCurrentUser.GetUser().id;
                prj.sort    = sort;
                //prj.donem_sayisi = 0;
                prj.parent_vid = 0;
                prj.durum      = TamamlamaDurumlari.bekliyor;
                //prj.periyot_suresi = 0;
                prj.periyot_turu      = 0;
                prj.mevcut_donem      = 0;
                prj.tur               = ProjeSurecTur.proje;
                prj.tamamlanma_tarihi = DateTime.Now;

                string          isimControl   = "select * from proje_surec where tur = " + ProjeSurecTur.proje + " and flag != " + durumlar.silindi.ToString() + " and isim = '" + prj.isim + "' and firma_id = " + prj.firma_id;
                ProjeSurecModel isimKontrolPs = db.Database.SqlQuery <ProjeSurecModel>(isimControl).FirstOrDefault();
                if (isimKontrolPs != null)
                {
                    return("proje_isim_hatasi");
                }

                bool kullaniciKontrol = firmaProjeKontrol(prj.firma_id, prj.id).Result;
                if (!kullaniciKontrol)
                {
                    return("proje_sayisi_hatasi");
                }

                db.proje_surec.Add(prj);
                db.SaveChanges();

                /*int musteri_id = Convert.ToInt32(Request["musteri_id"].ToString());
                 * if (musteri_id != 0)
                 * {
                 *  proje_surec dbPs = db.proje_surec.Where(e => e.vid == prj.vid).FirstOrDefault();
                 *  proje_musteri pm = db.proje_musteri.Where(e => e.flag == durumlar.aktif && e.proje_id == dbPs.id).FirstOrDefault();
                 *  if (pm == null)
                 *  {
                 *      pm = new proje_musteri();
                 *      pm.date = DateTime.Now;
                 *      pm.flag = durumlar.aktif;
                 *      pm.musteri_id = musteri_id;
                 *      pm.proje_id = dbPs.id;
                 *      int vidPm = 1;
                 *      if (db.proje_musteri.Count() != 0)
                 *      {
                 *          vidPm = db.proje_musteri.Max(e => e.vid) + 1;
                 *      }
                 *      int sortPm = 1;
                 *      if (db.proje_musteri.Count() != 0)
                 *      {
                 *          sortPm = db.proje_musteri.Max(e => e.sort) + 1;
                 *      }
                 *      pm.sort = sortPm;
                 *      pm.vid = vidPm;
                 *      db.proje_musteri.Add(pm);
                 *      db.SaveChanges();
                 *  }
                 *  else if (pm != null && pm.musteri_id != musteri_id)
                 *  {
                 *      pm.musteri_id = musteri_id;
                 *      db.Entry(pm).State = EntityState.Modified;
                 *      db.SaveChanges();
                 *  }
                 * }
                 * else if (musteri_id == 0)
                 * {
                 *  proje_surec dbPs = db.proje_surec.Where(e => e.vid == prj.vid).FirstOrDefault();
                 *  proje_musteri pm = db.proje_musteri.Where(e => e.flag == durumlar.aktif && e.proje_id == dbPs.id).FirstOrDefault(); if (pm != null && pm.musteri_id != musteri_id)
                 *      if (pm != null)
                 *      {
                 *          pm.flag = durumlar.silindi;
                 *          db.Entry(pm).State = EntityState.Modified;
                 *          db.SaveChanges();
                 *      }
                 * }*/

                return(prj.url);
            }
            catch (Exception e)
            {
                return("");
            }
        }