Esempio n. 1
0
        public bool Update(int id, LicenserInfoModel model)
        {
            try
            {
                using (var db = new LicenseDbEntities())
                {
                    var dbModel = db.LicenseOwners.FirstOrDefault(x => x.Id == id);
                    if (dbModel != null)
                    {
                        var result = DbHelper.CreateDbModel(model, dbModel);

                        db.SaveChanges();

                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                var error = ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors;
                _logger.Log(LogLevel.Error, ex);

                throw;
            }
        }
Esempio n. 2
0
        public static LicenserInfoModel FromDbModel(LicenseOwner model)
        {
            if (model == null)
            {
                return(null);
            }

            var result = new LicenserInfoModel();

            result.Id            = model.Id;
            result.Name          = model.Name;
            result.Phone         = model.Phone;
            result.Email         = model.Email;
            result.ContactPerson = model.ContactPerson;
            result.CompanyId     = (model.CompanyId ?? string.Empty).Trim();
            result.IsCompany     = model.IsCompany;
            result.EGN           = (model.EGN ?? string.Empty).Trim();
            result.IsDemo        = model.Licenses.All(x => x.IsDemo);
            result.RegNom        = model.RegNom;

            var extraInfo = model.LicenseOwnerExtraInfoes1.FirstOrDefault();

            if (extraInfo != null)
            {
                result.AccountingPerson = extraInfo.AccountingPerson;
                result.ContactPerson    = extraInfo.ContactPerson;
                result.VATRegistration  = extraInfo.VatRegistration ?? false;
                result.MOL                 = extraInfo.MOL;
                result.PostAddress         = extraInfo.PostAddress;
                result.PostCode            = extraInfo.PostCode ?? 0;
                result.RegistrationAddress = extraInfo.RegistrationAddress;
            }

            return(result);
        }
Esempio n. 3
0
        public static LicenseOwner CreateDbModel(LicenserInfoModel model, LicenseOwner dbModel = null)
        {
            var result = dbModel ?? new LicenseOwner();

            result.Name          = model.Name;
            result.Phone         = model.Phone;
            result.Email         = model.Email;
            result.ContactPerson = model.ContactPerson;
            result.CompanyId     = model.IsCompany ? model.CompanyId.Trim() : null;
            result.EGN           = !model.IsCompany ? model.EGN.Trim() : null;
            result.IsCompany     = model.IsCompany;
            result.RegNom        = model.RegNom;

            if (!model.IsDemo)
            {
                var extraInfo = result.LicenseOwnerExtraInfoes1.FirstOrDefault();
                if (extraInfo == null)
                {
                    extraInfo = new LicenseOwnerExtraInfo1();
                    result.LicenseOwnerExtraInfoes1.Add(extraInfo);
                }

                extraInfo.AccountingPerson = model.AccountingPerson;
                extraInfo.ContactPerson    = model.ContactPerson;
                extraInfo.VatRegistration  = model.VATRegistration;
                extraInfo.MOL                 = model.MOL;
                extraInfo.PostAddress         = model.PostAddress;
                extraInfo.PostCode            = model.PostCode;
                extraInfo.RegistrationAddress = model.RegistrationAddress;
            }
            return(result);
        }
Esempio n. 4
0
 public CreateLicenseOwnerModel(LicenserInfoModel model)
 {
     Id                  = model.Id;
     Name                = model.Name;
     IsDemo              = model.IsDemo;
     IsCompany           = model.IsCompany;
     Phone               = model.Phone;
     Email               = model.Email;
     CompanyId           = model.CompanyId.Trim();
     EGN                 = model.EGN.Trim();
     PostCode            = model.PostCode;
     RegistrationAddress = model.RegistrationAddress;
     PostAddress         = model.PostAddress;
     MOL                 = model.MOL;
     AccountingPerson    = model.AccountingPerson;
     VATRegistration     = model.VATRegistration;
     ContactPerson       = model.ContactPerson;
 }
Esempio n. 5
0
        public bool Create(LicenserInfoModel model)
        {
            try
            {
                using (var db = new LicenseDbEntities())
                {
                    var result = DbHelper.CreateDbModel(model);

                    db.LicenseOwners.Add(result);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                var error = ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors;
                _logger.Log(LogLevel.Error, ex);

                throw;
            }
        }