public ReturnMessageModel CreateEditResourceAuthor(ResourceAuthorModel raModel)
        {
            try
            {
                using (PointOfSaleEntities _context = new PointOfSaleEntities())
                {
                    var rtRow = _context.ResourceAuthors.Where(x => x.AuthorId == raModel.AuthorId).FirstOrDefault();
                    if (rtRow == null)
                    {
                        rtRow = new ResourceAuthor();
                    }

                    rtRow.Author      = raModel.Author;
                    rtRow.Nationality = raModel.Nationality;
                    rtRow.Genere      = raModel.Genere;
                    rtRow.IsActive    = raModel.IsActive;

                    if (raModel.AuthorId == 0)
                    {
                        rtRow.CreatedBy   = WebSecurity.CurrentUserId;
                        rtRow.CreatedDate = System.DateTime.Now;
                        _context.ResourceAuthors.Add(rtRow);
                        _context.SaveChanges();
                    }
                    else
                    {
                        rtRow.ModifiedBy   = WebSecurity.CurrentUserId;
                        rtRow.ModifiedDate = System.DateTime.Now;
                        _context.ResourceAuthors.Attach(rtRow);
                        _context.Entry(rtRow).State = EntityState.Modified;
                        _context.SaveChanges();
                    }



                    rModel.Msg     = "Resource Type Saved Successfully";
                    rModel.Success = true;
                    return(rModel);
                }
            }
            catch (Exception ex)
            {
                rModel.Msg     = "Resource Type Saved Failed";
                rModel.Success = false;
                return(rModel);
            }
        }
Beispiel #2
0
        public ReturnMessageModel CreateEditCountry(CountryModel cModel)
        {
            try
            {
                using (PointOfSaleEntities _context = new PointOfSaleEntities())
                {
                    var rtRow = _context.Countries.Where(x => x.CountryId == cModel.CountryId).FirstOrDefault();
                    if (rtRow == null)
                    {
                        rtRow = new Country();
                    }

                    rtRow.CountryName = cModel.CountryName;
                    rtRow.IsActive    = cModel.IsActive;


                    if (cModel.CountryId == 0)
                    {
                        rtRow.CreatedBy   = WebSecurity.CurrentUserId;
                        rtRow.CreatedDate = System.DateTime.Now;
                        _context.Countries.Add(rtRow);
                        _context.SaveChanges();
                    }
                    else
                    {
                        rtRow.ModifiedBy   = WebSecurity.CurrentUserId;
                        rtRow.ModifiedDate = System.DateTime.Now;
                        _context.Countries.Attach(rtRow);
                        _context.Entry(rtRow).State = EntityState.Modified;
                        _context.SaveChanges();
                    }

                    rModel.Msg     = "Country Saved Successfully";
                    rModel.Success = true;
                    return(rModel);
                }
            }
            catch (Exception ex)
            {
                rModel.Msg     = "Country Saved Failed";
                rModel.Success = false;
                return(rModel);
            }
        }
        public ReturnMessageModel CreateEditConfigChoiceCategory(ConfigChoiceCategoryModel iModel)
        {
            try
            {
                var cccRow = _context.ConfigChoiceCategories.Where(x => x.CategoryId == iModel.CategoryId).FirstOrDefault();
                if (cccRow == null)
                {
                    cccRow = new ConfigChoiceCategory();
                }

                cccRow.Category            = iModel.Category;
                cccRow.CategoryNepali      = iModel.CategoryNepali;
                cccRow.CategoryDescription = iModel.CategoryDescription;
                cccRow.IsActive            = iModel.IsActive;
                if (cccRow.CategoryId == 0)
                {
                    _context.ConfigChoiceCategories.Add(cccRow);
                    _context.SaveChanges();
                }
                else
                {
                    _context.ConfigChoiceCategories.Attach(cccRow);
                    _context.Entry(cccRow).State = EntityState.Modified;
                    _context.SaveChanges();
                }

                rModel.Msg     = "ConfigChoiceCategory Saved Successfully!!";
                rModel.Success = true;
                return(rModel);
            }
            catch (Exception ex)
            {
                rModel.Msg     = "ConfigChoiceCategory Save Failed!!";
                rModel.Success = false;
                return(rModel);
            }
        }
        public ReturnMessageModel CreateResourceGeneration(ResourceGenerationModel rgModel)
        {
            try
            {
                using (PointOfSaleEntities _context = new PointOfSaleEntities())
                {
                    var rtRow = _context.ResourceGenerations.Where(x => x.GenerationId == rgModel.GenerationId).FirstOrDefault();

                    if (rtRow == null)
                    {
                        rtRow = new ResourceGeneration();
                    }
                    rtRow.ResourceId = rgModel.ResourceId;
                    //rtRow.GenerationDate = rgModel.GenerationDate;
                    rtRow.GenerationCopyCount = rgModel.GenerationCopyCount;
                    rtRow.Remarks             = rgModel.Remarks;


                    if (rgModel.GenerationId == 0)
                    {
                        rtRow.GenerationDate = System.DateTime.Now;
                        _context.ResourceGenerations.Add(rtRow);
                        _context.SaveChanges();
                    }
                    else
                    {
                        _context.ResourceGenerations.Attach(rtRow);
                        _context.Entry(rtRow).State = EntityState.Modified;
                        _context.SaveChanges();
                    }


                    var gRow = _context.ResourceCopies.Where(x => x.ResourceCopyId == rgModel.ResourceCopyId).FirstOrDefault();
                    if (gRow == null)
                    {
                        gRow = new ResourceCopy();
                    }

                    for (int i = 1; i < rgModel.GenerationCopyCount; i++)
                    {
                        gRow.ResourceCopyId    = rgModel.ResourceCopyId;
                        gRow.ResourceId        = rgModel.ResourceId;
                        gRow.GenerationId      = rgModel.GenerationId;
                        gRow.ResourceCopyCount = i;
                        //gRow.ResourceCopyNumber = ResourceId.ToString() + rgModel.GenerationId + rgModel.ResourceCopyId;
                    }
                    //rtRow.GenerationId


                    rModel.Msg     = "Resource Type Saved Successfully";
                    rModel.Success = true;
                    return(rModel);
                }
            }
            catch (Exception ex)
            {
                rModel.Msg     = "Resource Type Saved Failed";
                rModel.Success = false;
                return(rModel);
            }
        }