Пример #1
0
        public UtilityModel GetUtilityInfo(int UtilityID = 0)
        {
            ShomaRMEntities db    = new ShomaRMEntities();
            UtilityModel    model = new UtilityModel();

            model.UtilityID      = 0;
            model.UtilityTitle   = "";
            model.UtilityDetails = "";

            var UtilityInfo = db.tbl_Utility.Where(p => p.UtilityID == UtilityID).FirstOrDefault();

            if (UtilityInfo != null)
            {
                model.UtilityID      = UtilityInfo.UtilityID;
                model.UtilityTitle   = UtilityInfo.UtilityTitle;
                model.UtilityDetails = UtilityInfo.UtilityDetails;
            }

            return(model);
        }
Пример #2
0
        public long SaveUpdateUtility(UtilityModel model)
        {
            ShomaRMEntities db            = new ShomaRMEntities();
            var             utilityExists = db.tbl_Utility.Where(p => p.UtilityID != model.UtilityID && p.UtilityTitle == model.UtilityTitle).FirstOrDefault();

            if (utilityExists == null)
            {
                if (model.UtilityID == 0)
                {
                    var data = new tbl_Utility()
                    {
                        UtilityTitle   = model.UtilityTitle,
                        UtilityDetails = model.UtilityDetails,
                    };
                    db.tbl_Utility.Add(data);
                    db.SaveChanges();
                    model.UtilityID = data.UtilityID;
                }
                else
                {
                    var utilityInfo = db.tbl_Utility.Where(p => p.UtilityID == model.UtilityID).FirstOrDefault();
                    if (utilityInfo != null)
                    {
                        utilityInfo.UtilityTitle   = model.UtilityTitle;
                        utilityInfo.UtilityDetails = model.UtilityDetails;
                        db.SaveChanges();
                    }
                    else
                    {
                        throw new Exception(model.UtilityTitle + " not exists in the system.");
                    }
                }

                return(model.UtilityID);
            }
            else
            {
                throw new Exception(model.UtilityTitle + " already exists in the system.");
            }
        }