public Project BindProject(Project model, Guid recordId)
        {
            crm_projects project = new crm_projects();

            project = this.GetProject(recordId);

            model.project_name        = project.project_name;
            model.project_description = project.project_description;
            model.project_type_id     = project.project_type_id.ToString();
            model.note      = project.note;
            model.is_active = project.is_active.Value;

            if (project.birey_id != null && GlobalHelper.IsGuidOrEmpty(project.birey_id.ToString()))
            {
                model.birey_id = project.birey_id.ToString();
            }

            if (project.kurum_id != null && GlobalHelper.IsGuidOrEmpty(project.kurum_id.ToString()))
            {
                model.kurum_id = project.kurum_id.ToString();
            }

            if (project.statik.Value != null && GlobalHelper.IsGuidOrEmpty(project.statik.ToString()))
            {
                model.statik = project.statik.Value.ToString();
            }

            if (project.elektrik.Value != null && GlobalHelper.IsGuidOrEmpty(project.elektrik.ToString()))
            {
                model.elektrik = project.elektrik.Value.ToString();
            }

            if (project.mekanik.Value != null && GlobalHelper.IsGuidOrEmpty(project.mekanik.ToString()))
            {
                model.mekanik = project.mekanik.Value.ToString();
            }

            if (project.harita.Value != null && GlobalHelper.IsGuidOrEmpty(project.harita.ToString()))
            {
                model.harita = project.harita.Value.ToString();
            }

            if (project.yapı_denetimi.Value != null && GlobalHelper.IsGuidOrEmpty(project.yapı_denetimi.ToString()))
            {
                model.yapi_denetim = project.yapı_denetimi.Value.ToString();
            }

            if (project.metre_kare != null)
            {
                model.proje_metrekare = project.metre_kare.Value.ToString();
                model.proje_metrekare = model.proje_metrekare.Replace(',', '.');
            }
            model.isveren_mobil_phone = project.isveren_mobile_phone;

            return(model);
        }
        public Project DeleteProject(Project model, Guid recordId)
        {
            crm_projects project = new crm_projects();

            project = this.GetProject(recordId);

            project.is_deleted = true;
            project.is_active  = false;
            project.deleted_at = DateTime.UtcNow;
            project.deleted_by = SessionContext.Current.ActiveUser.UserUid;

            this.Kaydet();
            return(model);
        }
        public Project UpdateProject(Project model, Guid recordId)
        {
            crm_projects project = new crm_projects();

            project = this.GetProject(recordId);

            project.project_name        = model.project_name;
            project.project_description = model.project_description;
            project.project_type_id     = Convert.ToInt32(model.project_type_id);
            project.note      = model.note;
            project.is_active = model.is_active;

            if (model.birey_id != null && GlobalHelper.IsGuidOrEmpty(model.birey_id))
            {
                project.birey_id = Guid.Parse(model.birey_id);
            }

            if (model.kurum_id != null && GlobalHelper.IsGuidOrEmpty(model.kurum_id))
            {
                project.kurum_id = Guid.Parse(model.kurum_id);
            }

            if (model.statik != null && GlobalHelper.IsGuidOrEmpty(model.statik))
            {
                project.statik = Guid.Parse(model.statik);
            }

            if (model.elektrik != null && GlobalHelper.IsGuidOrEmpty(model.elektrik))
            {
                project.elektrik = Guid.Parse(model.elektrik);
            }

            if (model.mekanik != null && GlobalHelper.IsGuidOrEmpty(model.mekanik))
            {
                project.mekanik = Guid.Parse(model.mekanik);
            }

            if (model.harita != null && GlobalHelper.IsGuidOrEmpty(model.harita))
            {
                project.harita = Guid.Parse(model.harita);
            }

            if (model.yapi_denetim != null && GlobalHelper.IsGuidOrEmpty(model.yapi_denetim))
            {
                project.yapı_denetimi = Guid.Parse(model.yapi_denetim);
            }

            if (model.proje_metrekare != null)
            {
                project.metre_kare = Convert.ToDecimal(model.proje_metrekare, CultureInfo.InvariantCulture);
            }

            project.isveren_mobile_phone = model.isveren_mobil_phone;

            if (project.project_type_id == 1)
            {
                project.kurum_id = Guid.Empty;
            }
            else if (project.project_type_id == 2)
            {
                project.birey_id = Guid.Empty;
            }

            project.updated_at = DateTime.UtcNow;
            project.updated_by = SessionContext.Current.ActiveUser.UserUid;

            this.Kaydet();
            return(model);
        }
        public void AddProject(crm_projects project, Project model)
        {
            project.project_id = Guid.NewGuid();

            if (GlobalHelper.IsGuidOrEmpty(model.birey_id))
            {
                project.birey_id = Guid.Parse(model.birey_id);
            }

            if (GlobalHelper.IsGuidOrEmpty(model.kurum_id))
            {
                project.kurum_id = Guid.Parse(model.kurum_id);
            }

            if (GlobalHelper.IsGuidOrEmpty(model.statik))
            {
                project.statik = Guid.Parse(model.statik);
            }

            if (GlobalHelper.IsGuidOrEmpty(model.elektrik))
            {
                project.elektrik = Guid.Parse(model.elektrik);
            }

            if (GlobalHelper.IsGuidOrEmpty(model.mekanik))
            {
                project.mekanik = Guid.Parse(model.mekanik);
            }

            if (GlobalHelper.IsGuidOrEmpty(model.harita))
            {
                project.harita = Guid.Parse(model.harita);
            }

            if (GlobalHelper.IsGuidOrEmpty(model.yapi_denetim))
            {
                project.yapı_denetimi = Guid.Parse(model.yapi_denetim);
            }

            if (model.proje_metrekare != null)
            {
                project.metre_kare = Convert.ToDecimal(model.proje_metrekare, CultureInfo.InvariantCulture);
            }

            project.isveren_mobile_phone = model.isveren_mobil_phone;

            if (project.project_type_id == 1)
            {
                project.kurum_id = Guid.Empty;
            }
            else if (project.project_type_id == 2)
            {
                project.birey_id = Guid.Empty;
            }

            project.project_name        = model.project_name;
            project.project_description = model.project_description;
            project.project_type_id     = Convert.ToInt32(model.project_type_id);
            project.note      = model.note;
            project.is_active = model.is_active;

            db.crm_projects.Add(project);
            this.Kaydet();
        }
        public ActionResult Projects(Project model)
        {
            Guid            recordId = Guid.Empty;
            CrmRepository   crmDB    = RepositoryManager.GetRepository <CrmRepository>();
            GenelRepository gnlDB    = RepositoryManager.GetRepository <GenelRepository>();

            #region Ortak Set Edilecek Değerler
            SessionContext.Current.ActiveUser.MenuId = model.MenuId;
            ViewBag.Success = true;
            #endregion

            model.activeKurumlar         = crmDB.GetKurumList();
            model.activeBireyler         = crmDB.GetBireyList();
            model.activeUsers            = gnlDB.GetActiveUsers();
            model.projectTypes           = crmDB.GetProjectTypeList();
            model.activeBireylerKurumlar = crmDB.GetBireyKurumList();
            model.project_type_id        = "1";

            ModelState.Remove("is_active");

            if (model.FromDeleteButton == "1")
            {
                if (GlobalHelper.IsGuid(model.RecordId))
                {
                    crmDB.DeleteProject(model, Guid.Parse(model.RecordId));
                    return(RedirectToAction("ListPage", "General", new { MenuId = Dcm.Source.GlobalHelper.Encrypt(model.MenuId) }));
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    if (GlobalHelper.IsGuid(model.RecordId))
                    {
                        recordId = Guid.Parse(model.RecordId);
                        try
                        {
                            model = crmDB.UpdateProject(model, recordId);

                            if (model.birey_id != null && GlobalHelper.IsGuidOrEmpty(model.birey_id))
                            {
                                model.birey_id = model.birey_id.ToString();
                            }

                            if (model.kurum_id != null && GlobalHelper.IsGuidOrEmpty(model.kurum_id))
                            {
                                model.kurum_id = model.kurum_id.ToString();
                            }


                            if (model.statik != null && GlobalHelper.IsGuidOrEmpty(model.statik))
                            {
                                model.statik = model.statik.ToString();
                            }

                            if (model.mekanik != null && GlobalHelper.IsGuidOrEmpty(model.mekanik))
                            {
                                model.mekanik = model.mekanik.ToString();
                            }

                            if (model.elektrik != null && GlobalHelper.IsGuidOrEmpty(model.elektrik))
                            {
                                model.elektrik = model.elektrik.ToString();
                            }

                            if (model.harita != null && GlobalHelper.IsGuidOrEmpty(model.harita))
                            {
                                model.harita = model.harita.ToString();
                            }

                            if (model.yapi_denetim != null && GlobalHelper.IsGuidOrEmpty(model.yapi_denetim))
                            {
                                model.yapi_denetim = model.yapi_denetim.ToString();
                            }

                            if (model.isveren_mobil_phone != null)
                            {
                                model.isveren_mobil_phone = model.isveren_mobil_phone.ToString();
                            }

                            if (model.proje_metrekare != null && !string.IsNullOrEmpty(model.proje_metrekare.ToString()))
                            {
                                model.proje_metrekare = model.proje_metrekare.ToString();
                            }



                            ViewBag.ResultMessage = Resources.GlobalResource.transaction_success;
                        }
                        catch (Exception exp)
                        {
                            ViewBag.Success = false;
                            ModelState.AddModelError("Error", exp.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            crm_projects project = new crm_projects();
                            crmDB.AddProject(project, model);
                            model.RecordId = project.project_id.ToString();

                            if (project.birey_id != null)
                            {
                                model.birey_id = project.birey_id.ToString();
                            }

                            if (project.kurum_id != null)
                            {
                                model.kurum_id = project.kurum_id.ToString();
                            }

                            if (project.statik != null)
                            {
                                model.statik = project.statik.ToString();
                            }

                            if (project.mekanik != null)
                            {
                                model.mekanik = project.mekanik.ToString();
                            }

                            if (project.elektrik != null)
                            {
                                model.elektrik = project.elektrik.ToString();
                            }

                            if (project.harita != null)
                            {
                                model.harita = project.harita.ToString();
                            }

                            if (project.yapı_denetimi != null)
                            {
                                model.yapi_denetim = project.yapı_denetimi.ToString();
                            }

                            if (project.isveren_mobile_phone != null)
                            {
                                model.isveren_mobil_phone = project.isveren_mobile_phone.ToString();
                            }

                            if (project.metre_kare != null && !string.IsNullOrEmpty(model.proje_metrekare.ToString()))
                            {
                                model.proje_metrekare = project.metre_kare.ToString();
                                model.proje_metrekare = model.proje_metrekare.Replace(',', '.');
                            }

                            ViewBag.ResultMessage = Resources.GlobalResource.transaction_success;
                        }
                        catch (Exception exp)
                        {
                            ViewBag.Success = false;
                            ModelState.AddModelError("Error", exp.Message);
                        }
                    }
                }
                else
                {
                    ViewBag.Success = false;
                }
            }

            return(View(model));
        }